import CancelablePromise from './CancelablePromise.js'; import './Promise.js'; /** * Represents an async task. */ interface Task { /** * Returns the current running state. */ isRunning(): boolean; /** * Cancels the current execution. */ cancel(): void; /** * Runs the task as early as possible. * Cancels the last execution. * @param args the arguments given to the task function. * @returns the promise. */ run(...args: Args): CancelablePromise; /** * Runs the task delayed. * Cancels the last execution. * @param delay milliseconds to wait until task execution * @param args the arguments given to the task function. * @returns the promise. */ delay(delay: number, ...args: Args): CancelablePromise; /** * Runs the task delayed. But only if it is not waiting for execution or executing. * Does not cancel the last execution. * @param delay milliseconds to wait until next task execution. * @param args the arguments given to the task function. If queued again. * @returns the promise. */ delayIfNotQueued(delay: number, ...args: Args): CancelablePromise; } /** * Wraps a callback into a task object which can be used to control the async execution of it. * * @example * ```ts * import AsyncTask from "apprt-core/AsyncTask"; * const task = AsyncTask(x => x * 200); * const r = await task.run(2); * assert.strictEqual(r, 400); * ``` */ declare function createTask(callback: (...args: Args) => Result | PromiseLike): Task; /** * Creates an async task without a callback. */ declare function createTask(): Task<[], void>; export { createTask, createTask as default }; export type { Task };