Skip to content

Commit

Permalink
$mol_wire_task restore jit optimized
Browse files Browse the repository at this point in the history
  • Loading branch information
zerkalica committed Nov 4, 2024
1 parent 5277bb0 commit dea4df5
Showing 1 changed file with 31 additions and 38 deletions.
69 changes: 31 additions & 38 deletions wire/task/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit dea4df5

Please sign in to comment.