Auto resolve promises in repl
This commit is contained in:
parent
901566d1ff
commit
d6f99f57b7
@ -5,6 +5,21 @@ const Kredits = require('../lib/kredits');
|
|||||||
|
|
||||||
const getNetworkId = require('./helpers/networkid.js')
|
const getNetworkId = require('./helpers/networkid.js')
|
||||||
|
|
||||||
|
function promiseEval (repl) {
|
||||||
|
const currentEval = repl.eval;
|
||||||
|
return function (cmd, context, filename, callback) {
|
||||||
|
currentEval(cmd, context, filename, (err, result) => {
|
||||||
|
if (result && typeof result.then === 'function') {
|
||||||
|
console.log('...waiting for promise to resolve');
|
||||||
|
return result
|
||||||
|
.then(response => callback(null, response))
|
||||||
|
.catch(err => callback(err, null));
|
||||||
|
}
|
||||||
|
return callback(err, result);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = async function(callback) {
|
module.exports = async function(callback) {
|
||||||
const networkId = await getNetworkId(web3)
|
const networkId = await getNetworkId(web3)
|
||||||
const provider = new ethers.providers.Web3Provider(
|
const provider = new ethers.providers.Web3Provider(
|
||||||
@ -16,6 +31,7 @@ module.exports = async function(callback) {
|
|||||||
let r = REPL.start();
|
let r = REPL.start();
|
||||||
r.context.kredits = kredits;
|
r.context.kredits = kredits;
|
||||||
r.context.web3 = web3;
|
r.context.web3 = web3;
|
||||||
|
r.eval = promiseEval(r);
|
||||||
|
|
||||||
r.on('exit', () => {
|
r.on('exit', () => {
|
||||||
console.log('Bye');
|
console.log('Bye');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user