Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Commit b95cd1b

Browse files
In domain-task, ensure completion callback always fires asynchronously
1 parent c44ceeb commit b95cd1b

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/Microsoft.AspNet.SpaServices/npm/domain-task/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "domain-task",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Tracks outstanding operations for a logical thread of execution",
55
"main": "main.js",
66
"scripts": {

src/Microsoft.AspNet.SpaServices/npm/domain-task/src/main.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ export function addTask(task: PromiseLike<any>) {
99
state.numRemainingTasks++;
1010
task.then(() => {
1111
// The application may have other listeners chained to this promise *after*
12-
// this listener. Since we don't want the combined task to complete until
13-
// all the handlers for child tasks have finished, delay the following by
14-
// one tick.
12+
// this listener, which may in turn register further tasks. Since we don't
13+
// want the combined task to complete until all the handlers for child tasks
14+
// have finished, delay the response to give time for more tasks to be added
15+
// synchronously.
1516
setTimeout(() => {
1617
state.numRemainingTasks--;
1718
if (state.numRemainingTasks === 0 && !state.hasIssuedSuccessCallback) {
1819
state.hasIssuedSuccessCallback = true;
19-
state.completionCallback(/* error */ null);
20+
setTimeout(() => {
21+
state.completionCallback(/* error */ null);
22+
}, 0);
2023
}
2124
}, 0);
2225
}, (error) => {
@@ -42,7 +45,9 @@ export function run<T>(codeToRun: () => T, completionCallback: (error: any) => v
4245
// If no tasks were registered synchronously, then we're done already
4346
if (state.numRemainingTasks === 0 && !state.hasIssuedSuccessCallback) {
4447
state.hasIssuedSuccessCallback = true;
45-
state.completionCallback(/* error */ null);
48+
setTimeout(() => {
49+
state.completionCallback(/* error */ null);
50+
}, 0);
4651
}
4752
} catch(ex) {
4853
state.completionCallback(ex);

0 commit comments

Comments
 (0)