computes-vm
Version:
Computes virtual machine
43 lines (33 loc) • 1.07 kB
text/coffeescript
CallbackComponent = require 'computes-component-callback'
path = require 'path'
class Function extends CallbackComponent
constructor: (options, dependencies={}) ->
{} = dependencies
?= require 'child_process'
super
onEnvelope: (envelope, callback) =>
child = .fork path.join( __dirname, './function-worker-runner.js')
child.send envelope
child.on 'message', (message) =>
return if
if message.type == 'error'
= true
child.kill 'SIGKILL'
callback new Error message.error
return
if message.type == 'ready'
setTimeout =>
return if
= true
child.kill 'SIGKILL'
callback new Error('Function took too long')
, 60000
return
if message.type == 'envelope'
= true
child.kill 'SIGKILL'
{envelope} = message
callback null, envelope.message
return
return child
module.exports = Function