diff --git a/package.json b/package.json index 03883f8..5393922 100644 --- a/package.json +++ b/package.json @@ -126,7 +126,7 @@ "test:watch": "eslint --fix && jest --updateSnapshot --watchAll" }, "types": "dist/index.d.ts", - "version": "1.1.0-alpha.16", + "version": "1.1.0-alpha.17", "dependencies": { "@webkrafters/eagleeye": "^1.0.8", "js-sha512": "^0.9.0", diff --git a/src/main/universe/index.tsx b/src/main/universe/index.tsx index 1a48181..f9144bd 100644 --- a/src/main/universe/index.tsx +++ b/src/main/universe/index.tsx @@ -146,7 +146,7 @@ class StreamerHandle implements Handle { return this._entry?.channel?.deref?.() as W } // istanbul ignore next - get size() { return this.isValid ? this._entry.numConnections : 0 } + get size() { return this.isValid ? this._entry.numConnections : -1 } // istanbul ignore next dec() { if( !this.isValid ) { return } @@ -154,8 +154,10 @@ class StreamerHandle implements Handle { if( this.size ) { return } this.resource.endStream(); this._chs.finalizer.unregister( this.resource ); + const { channel } = this._entry; this._entry.channel = null; this._chs.finalize( this._sMapHash ); + setTimeout( () => channel.deref()?.endStream(), 0 ); } inc() { this.isValid && this._entry.numConnections++ } } @@ -461,27 +463,3 @@ export class Utility { } export function createContext() { return new ObservableUniverse() } - -{/* function _makeStore< - T extends State, - S extends SelectorMap ->( channel : Channel ) { - const s = makeStore( channel ); - s.resetState = intercept( s.resetState ); - s.setState = intercept( s.setState ); - return s; -} */} - -// function intercept( m : IStore["resetState"] ); -// function intercept( m : IStore["setState"] ); -// function intercept( m : any ) { -// return ( ...args : Parameters ) => { -// try { m( ...args ) } catch( e ) { -// /* istanbul ignore next */ -// if( !e.message.startsWith( "Cannot read properties of null (reading 'getState')" ) ) { -// throw e; -// } -// // allow system gc to clean up scheduled freed streams -// } -// } -// }