Files
coopgo/node_modules/@react-dnd/asap/src/RawTask.ts
sgauthier 6e64e138e2
All checks were successful
Publish To Prod / deploy_and_publish (push) Successful in 35s
planning
2024-10-14 09:15:30 +02:00

25 lines
494 B
TypeScript

// We wrap tasks with recyclable task objects. A task object implements
import type { TaskFn, Task } from 'types'
// `call`, just like a function.
export class RawTask implements Task {
public task: TaskFn | null = null
public constructor(
private onError: (err: any) => void,
private release: (t: RawTask) => void,
) {}
public call() {
try {
this.task && this.task()
} catch (error) {
this.onError(error)
} finally {
this.task = null
this.release(this)
}
}
}