@ -1,4 +1,4 @@
import { DEFAULT_TIMER_SCOPE_SEPARATOR } from './consts.ts' ;
import { DEFAULT_TIMER_SCOPE_SEPARATOR , TIMER_STATUS_PENDING } from './consts.ts' ;
import type {
TimerEntrySnapshot ,
TimerKind ,
@ -31,6 +31,46 @@ export interface InternalTimerEntry {
meta? : Readonly < Record < string , unknown > > ;
}
export interface CreateInternalTimerEntryInput {
readonly id : number ;
readonly key : string ;
readonly kind : TimerKind ;
readonly task : TimerTask ;
readonly scheduledAt : number ;
readonly delayMs : number ;
readonly intervalMs : number | null ;
readonly awaitTask : boolean ;
readonly maxRuns : number | undefined ;
readonly removeOnComplete : boolean ;
readonly meta? : Readonly < Record < string , unknown > > ;
}
export function createInternalTimerEntry ( input : CreateInternalTimerEntryInput ) : InternalTimerEntry {
return {
id : input.id ,
key : input.key ,
version : 0 ,
kind : input.kind ,
status : TIMER_STATUS_PENDING ,
task : input.task ,
controller : new AbortController ( ) ,
native : null ,
scheduledAt : input.scheduledAt ,
dueAt : input.scheduledAt + input . delayMs ,
delayMs : input.delayMs ,
intervalMs : input.intervalMs ,
awaitTask : input.awaitTask ,
maxRuns : input.maxRuns ,
runCount : 0 ,
lastFiredAt : null ,
lastCompletedAt : null ,
lastErrorAt : null ,
error : null ,
removeOnComplete : input.removeOnComplete ,
meta : input.meta
} ;
}
export function scopeOfTimerKey ( key : string ) : string {
const idx = key . lastIndexOf ( DEFAULT_TIMER_SCOPE_SEPARATOR ) ;
return idx === - 1 ? key : key.slice ( 0 , idx ) ;