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

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -