Skip to content

Commit

Permalink
$mol_wire_task: catch and auto destruct promises
Browse files Browse the repository at this point in the history
  • Loading branch information
jin committed Dec 15, 2024
1 parent 73c4af6 commit 2f2d80b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
5 changes: 0 additions & 5 deletions wire/atom/atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,6 @@ namespace $ {

super.destructor()

const prev = this.cache
if( $mol_owning_check( this, prev ) ) {
prev.destructor()
}

if( this.pub_from === 0 ) {
;( this.host as any ?? this.task )[ this.field() ] = null
} else {
Expand Down
10 changes: 10 additions & 0 deletions wire/fiber/fiber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,16 @@ namespace $ {
}
} )
}

destructor() {

super.destructor()

if( $mol_owning_check( this, this.cache ) ) {
this.cache.destructor()
}

}

}

Expand Down
8 changes: 8 additions & 0 deletions wire/task/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ namespace $ {
this.cursor = $mol_wire_cursor.fresh
if( next !== prev ) this.emit()

if( $mol_owning_catch( this, next ) ) {
try {
(next as any)[ Symbol.toStringTag ] = (this as any)[ Symbol.toStringTag ]
} catch { // Promises throw in strict mode
Object.defineProperty( next, Symbol.toStringTag, { value: (this as any)[ Symbol.toStringTag ] } )
}
}

return next
}

Expand Down

0 comments on commit 2f2d80b

Please sign in to comment.