Skip to content

Commit

Permalink
$mol_wire_fiber: fixed promise destructor propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
jin committed Dec 12, 2024
1 parent c9485c5 commit 381921e
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions wire/fiber/fiber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,15 @@ namespace $ {

if( $mol_promise_like( result ) && !handled.has( result ) ) {

handled.add( result )
const put = ( res: Result )=> {
if( this.cache === result ) this.put( res )
return res
}
result = result.then( put, put )
result = Object.assign(
result.then( put, put ),
{ destructor: ( result as any ).destructor }
)

}

Expand All @@ -199,9 +203,13 @@ namespace $ {

if( $mol_promise_like( result ) && !handled.has( result ) ) {

result = result.finally( ()=> {
if( this.cache === result ) this.absorb()
} )
handled.add( result )
result = Object.assign(
result.finally( ()=> {
if( this.cache === result ) this.absorb()
} ),
{ destructor: ( result as any ).destructor }
)

}

Expand Down

0 comments on commit 381921e

Please sign in to comment.