Vm2: 비동기 μ½œλ°±μ—μ„œ 였λ₯˜ 처리

에 λ§Œλ“  2017λ…„ 02μ›” 03일  Β·  8μ½”λ©˜νŠΈ  Β·  좜처: patriksimek/vm2

비동기 μ½œλ°±μ—μ„œ 였λ₯˜λ₯Ό μ²˜λ¦¬ν•˜λŠ” 방법이 μžˆμŠ΅λ‹ˆκΉŒ?

const {NodeVM} = require('vm2');

const vm = new NodeVM({
    timeout: 10000,
    sandbox: {}
});

try {
  vm.run(`
    setInterval(() => {
      console.log("haha")
      process.exit()              // <--- can't find a way to intercept this!
    }, 1000);

    process.exit()
  `, 'code.js');
} catch(e) {
  console.log(e.message);
}


setInterval(() => {
  console.log("haha 2")
},1000);

전체 슀크립트 μΆ©λŒμ„ λ°©μ§€ν•˜λŠ” 방법을 μ°Ύκ³  μžˆμŠ΅λ‹ˆλ‹€.

feature request stale

κ°€μž₯ μœ μš©ν•œ λŒ“κΈ€

vm.run()을 domain.run()으둜 λž˜ν•‘ν•˜κ³  μž‘λ™ν•˜λŠ” 것 κ°™μŠ΅λ‹ˆλ‹€. λΆ€μž‘μš©μ΄ μžˆλŠ”μ§€λŠ” λͺ¨λ₯΄κ² μ§€λ§Œ..

let domain = Domain.create();
domain.on('error', (err) => {
    console.error('Asynchronous error while executing script.', err.stack);
});
domain.run(() => {
    try {
        vm.run(script, filename);
    } catch (err) {
        console.error('Synchronous error while executing script.', err.stack);
    }
});

λͺ¨λ“  8 λŒ“κΈ€

λ‹€μŒκ³Ό 같은 비동기 였λ₯˜λ₯Ό μ²˜λ¦¬ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

process.on('uncaughtException', (err) => {
    console.log(err);
})

이것은 VM 내뢀와 μ™ΈλΆ€ λͺ¨λ‘μ—μ„œ λͺ¨λ“  μ˜ˆμ™Έλ₯Ό ν¬μ°©ν•œλ‹€λŠ” 점에 μœ μ˜ν•˜μ‹­μ‹œμ˜€.

κ³ λ§ˆμ›Œ. λ„€, λΆ€λΆ„μ μœΌλ‘œ 도움이 λ˜μ—ˆμŠ΅λ‹ˆλ‹€. BTW, 'uncaughtException'의 였λ₯˜κ°€ VM(및 μ•„λ§ˆλ„ κ·Έ 쀑 μ–΄λŠ 것)κ³Ό 관련이 μžˆλŠ”μ§€ κ΅¬λ³„ν•˜λŠ” 방법이 μžˆμŠ΅λ‹ˆκΉŒ?

λΆˆν–‰νžˆλ„ ν˜„μž¬λŠ” μ•„λ‹™λ‹ˆλ‹€. 이것을 κ΅¬ν˜„ν•˜λŠ” 방법을 μ•Œκ³  μžˆμ§€λ§Œ μ‹œκ°„μ΄ μ’€ 걸릴 κ²ƒμž…λ‹ˆλ‹€.

vm.run()을 domain.run()으둜 λž˜ν•‘ν•˜κ³  μž‘λ™ν•˜λŠ” 것 κ°™μŠ΅λ‹ˆλ‹€. λΆ€μž‘μš©μ΄ μžˆλŠ”μ§€λŠ” λͺ¨λ₯΄κ² μ§€λ§Œ..

let domain = Domain.create();
domain.on('error', (err) => {
    console.error('Asynchronous error while executing script.', err.stack);
});
domain.run(() => {
    try {
        vm.run(script, filename);
    } catch (err) {
        console.error('Synchronous error while executing script.', err.stack);
    }
});

이 λ¬Έμ œλŠ” 졜근 ν™œλ™μ΄ μ—†μ—ˆκΈ° λ•Œλ¬Έμ— μžλ™μœΌλ‘œ 였래된 κ²ƒμœΌλ‘œ ν‘œμ‹œλ˜μ—ˆμŠ΅λ‹ˆλ‹€. 더 이상 ν™œλ™μ΄ μ—†μœΌλ©΄ νμ‡„λ©λ‹ˆλ‹€. κ·€ν•˜μ˜ 기여에 κ°μ‚¬λ“œλ¦½λ‹ˆλ‹€.

@alsterg 방법이 νš¨κ³Όκ°€

@patriksimek 이것을 μžŠμ–΄

@ImSingee 확인 방법은 λΆˆν–‰νžˆλ„ 더 이상 μž‘λ™ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.
비동기 였λ₯˜λ₯Ό μ²˜λ¦¬ν•˜λŠ” 방법에 λŒ€ν•œ μ—…λ°μ΄νŠΈκ°€ μžˆμŠ΅λ‹ˆκΉŒ?

이에 λŒ€ν•œ μ—…λ°μ΄νŠΈκ°€ μžˆμŠ΅λ‹ˆκΉŒ???

이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰