diff --git a/wire/task/task.ts b/wire/task/task.ts index 01fa4ac396..aef3f348b6 100644 --- a/wire/task/task.ts +++ b/wire/task/task.ts @@ -6,55 +6,48 @@ namespace $ { Args extends readonly unknown[], Result, > extends $mol_wire_fiber< Host, Args, Result > { - - static get< + + static getter< Host, Args extends readonly unknown[], Result, >( task: ( this : Host , ... args : Args )=> Result, - host: Host, - args: Args, - ) { - const sub = $mol_wire_auto() - const existen = sub?.track_next() as $mol_wire_task< Host, Args, Result > | undefined + ): ( host: Host, args: Args )=> $mol_wire_task< Host, Args, Result > { - reuse: if( existen ) { + return function $mol_wire_task_get( host: Host, args: Args ) { - if( !existen.temp ) break reuse + const sub = $mol_wire_auto() + const existen = sub?.track_next() as $mol_wire_task< Host, Args, Result > | undefined - if( existen.host !== host ) break reuse - if( existen.task !== task ) break reuse - if( !$mol_compare_deep( existen.args, args ) ) break reuse + reuse: if( existen ) { + + if( !existen.temp ) break reuse + + if( existen.host !== host ) break reuse + if( existen.task !== task ) break reuse + if( !$mol_compare_deep( existen.args, args ) ) break reuse + + return existen + } - return existen - } - - const key = ( (host as any)?.[ Symbol.toStringTag ] ?? host ) + ( '.' + task.name + '<#>' ) - const next = new $mol_wire_task( key, task, host, args ) - - // Disabled because non-idempotency is required for try-catch - if( existen?.temp ) { - $$.$mol_log3_warn({ - place: '$mol_wire_task', - message: `Non idempotency`, - existen, - next, - hint: 'Ignore it', - }) + const key = ( (host as any)?.[ Symbol.toStringTag ] ?? host ) + ( '.' + task.name + '<#>' ) + const next = new $mol_wire_task( key, task, host, args ) + + // Disabled because non-idempotency is required for try-catch + if( existen?.temp ) { + $$.$mol_log3_warn({ + place: '$mol_wire_task', + message: `Non idempotency`, + existen, + next, + hint: 'Ignore it', + }) + } + + return next } - return next - } - - static getter< - Host, - Args extends readonly unknown[], - Result, - >( - task: ( this : Host , ... args : Args )=> Result, - ) { - return (host: Host, args: Args) => this.get(task, host, args) } get temp() {