forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasyncAwaitBasic.js
More file actions
75 lines (67 loc) · 1.78 KB
/
asyncAwaitBasic.js
File metadata and controls
75 lines (67 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
var log;
if (typeof telemetryLog !== 'undefined') {
log = telemetryLog;
}
else if (typeof console !== 'undefined' && typeof console.log !== 'undefined') {
log = function (msg, shouldWrite) {
if (shouldWrite) {
console.log(msg);
}
}
}
else {
log = function (msg, shouldWrite) {
if (shouldWrite) {
WScript.Echo(msg);
}
};
}
var setTimeoutX;
if (typeof setTimeout !== 'undefined') {
setTimeoutX = setTimeout;
}
else {
setTimeoutX = WScript.SetTimeout;
}
var writeTTDLog;
if (typeof emitTTDLog === 'undefined') {
writeTTDLog = function (uri) {
// no-op
};
}
else {
writeTTDLog = emitTTDLog;
}
var ttdLogUriX;
if (typeof ttdLogURI !== 'undefined') {
ttdLogUriX = ttdLogURI;
}
/////////////////
async function f1(a, b, c) {
log('f1 starting', true);
return { a, b, c };
}
async function f2(d, e, f) {
log('f2 starting', true);
let x = await f1(d + 10, e + 20, f + 30);
return x;
}
async function f3() {
log('f3 starting', true);
var x = await f2(1, 2, 3);
var xstr = JSON.stringify(x, undefined, 0);
log(`x = ${xstr}`, true);
}
setTimeoutX(() => {
f3().then(() => {
log('done', true);
writeTTDLog(ttdLogUriX);
}, (err) => {
log(`error: ${err}`, true);
writeTTDLog(ttdLogUriX);
})
}, 20);