mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-02-20 02:58:05 +00:00
Merge pull request #731 from embark-framework/features/await-console
simple implementation of await in the console
This commit is contained in:
commit
7bd3202ad5
@ -41,7 +41,22 @@ class CodeRunner {
|
|||||||
if (!cb) {
|
if (!cb) {
|
||||||
cb = function() {};
|
cb = function() {};
|
||||||
}
|
}
|
||||||
|
const awaitIdx = code.indexOf('await');
|
||||||
|
if (awaitIdx > -1) {
|
||||||
|
if (awaitIdx < 2) {
|
||||||
|
let end = code.length;
|
||||||
|
if (code[end - 1] === ';') {
|
||||||
|
end--; // Remove the `;` because we add function calls
|
||||||
|
}
|
||||||
|
code = code.substring(5, end); // remove await keyword
|
||||||
|
} else {
|
||||||
|
code = `(async function() {${code}})();`;
|
||||||
|
}
|
||||||
|
}
|
||||||
let result = RunCode.doEval(code);
|
let result = RunCode.doEval(code);
|
||||||
|
if (result instanceof Promise) {
|
||||||
|
return result.then((value) => cb(null, value)).catch(cb);
|
||||||
|
}
|
||||||
if (forConsoleOnly && self.ipc.isServer()) {
|
if (forConsoleOnly && self.ipc.isServer()) {
|
||||||
self.commands.push({code});
|
self.commands.push({code});
|
||||||
self.ipc.broadcast("runcode:newCommand", {code});
|
self.ipc.broadcast("runcode:newCommand", {code});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user