/** * Copyright (c) 2017-2018 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal */ import { RuntimeContext } from './execution/runtime-context.js'; import { Progress } from './execution/progress.js'; /** A "named function wrapper" with built in "computation tree progress tracking". */ interface Task { /** run the task without observation */ run(): Promise; /** run the task with the specified observer, default updateRate is 250ms */ run(observer: Progress.Observer, updateRateMs?: number): Promise; /** * Run a child task that adds a new node to the progress tree. Allows to passing the progress so * that the progress tree can be kept in a "good state" without having to separately call update. */ runAsChild(ctx: RuntimeContext, progress?: string | Partial): Promise; /** Run the task on the specified context. */ runInContext(ctx: RuntimeContext): Promise; readonly id: number; readonly name: string; } declare namespace Task { function is(t: any): t is Task; interface Aborted { isAborted: true; reason: string; toString(): string; } function isAbort(e: any): e is Aborted; function Aborted(reason: string): Aborted; function create(name: string, f: (ctx: RuntimeContext) => Promise, onAbort?: () => void): Task; function constant(name: string, value: T): Task; function empty(): Task; function fail(name: string, reason: string): Task; function resolveInContext(object: Task | T, ctx?: RuntimeContext): T | Promise; interface Progress { taskId: number; taskName: string; startedTime: number; message: string; canAbort: boolean; isIndeterminate: boolean; current: number; max: number; } } export { Task };