in src/SyncTasks.ts [193:222]
private _addCallbackSet<U>(set: CallbackSet<T, U>, callbackWillChain: boolean): STPromise<U> {
const task = new SyncTask<U>();
task.onCancel(context => {
set.wasCanceled = true;
set.cancelContext = context;
// Note: Cancel due to bubbling should not throw if the public cancel is called before/after.
this._cancelInternal(context);
});
set.task = task;
this._storedCallbackSets.push(set);
if (callbackWillChain) {
// The callback inherits responsibility for "handling" errors.
this._mustHandleError = false;
} else {
// The callback can never "handle" errors since nothing can chain to it.
task._mustHandleError = false;
}
// The _resolve* functions handle callbacks being added while they are running.
if (!this._resolving) {
if (this._completedSuccess) {
this._resolveSuccesses();
} else if (this._completedFail) {
this._resolveFailures();
}
}
return task.promise();
}