Skip to content

Commit d231254

Browse files
committed
fix: ensure to wait
1 parent 52f4e26 commit d231254

1 file changed

Lines changed: 28 additions & 26 deletions

File tree

src/template/index.js

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,36 @@
33
const SERIALIZE_ERROR = require('./serialize-error')
44

55
module.exports = snippet => `
6-
const args = JSON.parse(process.argv[2])
6+
;(async () => {
7+
const args = JSON.parse(process.argv[2])
78
8-
/* https://github.com/Kikobeats/null-prototype-object */
9-
const logging = new (/* @__PURE__ */ (() => { let e = function(){}; return e.prototype = Object.create(null), Object.freeze(e.prototype), e })());
9+
/* https://github.com/Kikobeats/null-prototype-object */
10+
const logging = new (/* @__PURE__ */ (() => { let e = function(){}; return e.prototype = Object.create(null), Object.freeze(e.prototype), e })());
1011
11-
for (const method of ['log', 'info', 'debug', 'warn', 'error']) {
12-
console[method] = function (...args) {
13-
logging[method] === undefined ? logging[method] = [args] : logging[method].push(args)
12+
for (const method of ['log', 'info', 'debug', 'warn', 'error']) {
13+
console[method] = function (...args) {
14+
logging[method] === undefined ? logging[method] = [args] : logging[method].push(args)
15+
}
1416
}
15-
}
1617
17-
;(async (send) => {
18-
process.stdout.write = function () {}
19-
let value
20-
let isFulfilled
18+
;await (async (send) => {
19+
process.stdout.write = function () {}
20+
let value
21+
let isFulfilled
2122
22-
try {
23-
value = await (${snippet.toString()})(...args)
24-
isFulfilled = true
25-
} catch (error) {
26-
value = ${SERIALIZE_ERROR}(error)
27-
isFulfilled = false
28-
} finally {
29-
send(JSON.stringify({
30-
isFulfilled,
31-
logging,
32-
value,
33-
profiling: { memory: process.memoryUsage().rss }
34-
}))
35-
}
36-
})(process.stdout.write.bind(process.stdout))`
23+
try {
24+
value = await (${snippet.toString()})(...args)
25+
isFulfilled = true
26+
} catch (error) {
27+
value = ${SERIALIZE_ERROR}(error)
28+
isFulfilled = false
29+
} finally {
30+
send(JSON.stringify({
31+
isFulfilled,
32+
logging,
33+
value,
34+
profiling: { memory: process.memoryUsage().rss }
35+
}))
36+
}
37+
})(process.stdout.write.bind(process.stdout))
38+
})()`

0 commit comments

Comments
 (0)