This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(asynchooks): use asynchooks to handle native async/await
- Loading branch information
1 parent
1741e70
commit 4b52ea0
Showing
10 changed files
with
153 additions
and
261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
describe('native async/await', function() { | ||
const log: string[] = []; | ||
const zone = Zone.current.fork({ | ||
name: 'promise', | ||
onScheduleTask: (delegate: ZoneDelegate, curr: Zone, target: Zone, task: any) => { | ||
log.push('scheduleTask'); | ||
return delegate.scheduleTask(target, task); | ||
}, | ||
onInvokeTask: (delegate: ZoneDelegate, curr: Zone, target: Zone, task: any, applyThis: any, | ||
applyArgs: any) => { | ||
log.push('invokeTask'); | ||
return delegate.invokeTask(target, task, applyThis, applyArgs); | ||
} | ||
}); | ||
|
||
it('should still in zone after await', function(done) { | ||
async function asyncOutside() { | ||
return 'asyncOutside'; | ||
} | ||
|
||
const neverResolved = new Promise(() => {}); | ||
const waitForNever = new Promise((res, _) => { | ||
res(neverResolved); | ||
}); | ||
|
||
async function getNever() { | ||
return waitForNever; | ||
}; | ||
|
||
zone.run(async() => { | ||
const outside = await asyncOutside(); | ||
expect(outside).toEqual('asyncOutside'); | ||
expect(Zone.current.name).toEqual(zone.name); | ||
|
||
async function asyncInside() { | ||
return 'asyncInside'; | ||
}; | ||
|
||
const inside = await asyncInside(); | ||
expect(inside).toEqual('asyncInside'); | ||
expect(Zone.current.name).toEqual(zone.name); | ||
|
||
expect(log).toEqual(['scheduleTask', 'invokeTask', 'scheduleTask', 'invokeTask']); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.