javascript - Catching async errors from eval using domain -
i'm trying catch async errors npm eval
module. it's similar normal eval, except utilizes node's vm
module directly.
i came across node's domain
module. allows me catch async errors occur within _eval
.
however checked documentation , can't find done
event domain. how supposed know when resolve promise?
var code = [ "settimeout(function () {", " throw new error('async error sim')", "}, 1000)" ].join('\n') var domain = require('domain') var _eval = require('eval') var main = {} var evalasync = main.evalasync = function (code, file) { return new promise(function (resolve, reject) { var d = domain.create(); d.on('error', function (e) { return reject(e) }) var op = d.run(function () { return _eval(code, file, {}, true) }) // return resolve(op) }) } evalasync(code, 'hi.js', {}, true) .catch(function (e) { console.log(e) })
is there way can make evalasync
module catch errors , return values correctly?
i've tried this:
var op = d.run(function () { return _eval(code, file, {}, true) }) return resolve(op)
Comments
Post a Comment