From 2f2d80b00bbffcff75f045b9308fce564d568435 Mon Sep 17 00:00:00 2001 From: jin Date: Sun, 15 Dec 2024 15:58:35 +0300 Subject: [PATCH] $mol_wire_task: catch and auto destruct promises --- wire/atom/atom.ts | 5 ----- wire/fiber/fiber.ts | 10 ++++++++++ wire/task/task.ts | 8 ++++++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/wire/atom/atom.ts b/wire/atom/atom.ts index 8a646cd7c1..9f84833638 100644 --- a/wire/atom/atom.ts +++ b/wire/atom/atom.ts @@ -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 { diff --git a/wire/fiber/fiber.ts b/wire/fiber/fiber.ts index f02b8acec6..a6d3927b52 100644 --- a/wire/fiber/fiber.ts +++ b/wire/fiber/fiber.ts @@ -321,6 +321,16 @@ namespace $ { } } ) } + + destructor() { + + super.destructor() + + if( $mol_owning_check( this, this.cache ) ) { + this.cache.destructor() + } + + } } diff --git a/wire/task/task.ts b/wire/task/task.ts index aef3f348b6..a9e7673427 100644 --- a/wire/task/task.ts +++ b/wire/task/task.ts @@ -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 }