|
@@ -6,7 +6,7 @@
|
|
|
|
|
|
import { RuntimeContext } from './execution/runtime-context'
|
|
import { RuntimeContext } from './execution/runtime-context'
|
|
import { Progress } from './execution/progress'
|
|
import { Progress } from './execution/progress'
|
|
-import { ExecuteObservable, ExecuteObservableChild } from './execution/observable';
|
|
|
|
|
|
+import { ExecuteObservable, ExecuteObservableChild, ExecuteInContext } from './execution/observable';
|
|
import { SyncRuntimeContext } from 'mol-task/execution/synchronous';
|
|
import { SyncRuntimeContext } from 'mol-task/execution/synchronous';
|
|
|
|
|
|
// A "named function wrapper" with built in "computation tree progress tracking".
|
|
// A "named function wrapper" with built in "computation tree progress tracking".
|
|
@@ -21,6 +21,9 @@ interface Task<T> {
|
|
// Allow to pass the progress so that the progress tree can be kept in a "good state" without having to separately call update.
|
|
// Allow to pass 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<RuntimeContext.ProgressUpdate>): Promise<T>
|
|
runAsChild(ctx: RuntimeContext, progress?: string | Partial<RuntimeContext.ProgressUpdate>): Promise<T>
|
|
|
|
|
|
|
|
+ // Run the task on the specified context.
|
|
|
|
+ runInContext(ctx: RuntimeContext): Promise<T>
|
|
|
|
+
|
|
readonly id: number,
|
|
readonly id: number,
|
|
readonly name: string
|
|
readonly name: string
|
|
}
|
|
}
|
|
@@ -39,6 +42,11 @@ namespace Task {
|
|
return ExecuteObservableChild(ctx, this, progress as string | Partial<RuntimeContext.ProgressUpdate>);
|
|
return ExecuteObservableChild(ctx, this, progress as string | Partial<RuntimeContext.ProgressUpdate>);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ runInContext(ctx: RuntimeContext): Promise<T> {
|
|
|
|
+ if (ctx.isSynchronous) return this.f(SyncRuntimeContext);
|
|
|
|
+ return ExecuteInContext(ctx, this);
|
|
|
|
+ }
|
|
|
|
+
|
|
constructor(public name: string, public f: (ctx: RuntimeContext) => Promise<T>, public onAbort?: () => void) {
|
|
constructor(public name: string, public f: (ctx: RuntimeContext) => Promise<T>, public onAbort?: () => void) {
|
|
this.id = nextId();
|
|
this.id = nextId();
|
|
}
|
|
}
|