mirror of https://github.com/embarklabs/embark.git
feat(@embark/testing): introduce proper request2 api for async/await
This commit is contained in:
parent
dc9171a1e7
commit
c947517c0d
|
@ -40,7 +40,18 @@ class Events {
|
|||
|
||||
request2(cmd, ...args) {
|
||||
assert(this.commandHandlers[cmd], `command handler for ${cmd} not registered`);
|
||||
this.commandHandlers[cmd](...args);
|
||||
return new Promise((resolve, reject) => {
|
||||
args.push((err, ...res) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
if (res.length && res.length > 1) {
|
||||
return resolve(res);
|
||||
}
|
||||
return resolve(res[0]);
|
||||
});
|
||||
this.commandHandlers[cmd](...args);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue