UNPKG

computes-vm

Version:
73 lines (62 loc) 2.35 kB
// Generated by CoffeeScript 1.11.1 (function() { var CallbackComponent, Function, path, bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, hasProp = {}.hasOwnProperty; CallbackComponent = require('computes-component-callback'); path = require('path'); Function = (function(superClass) { extend(Function, superClass); function Function(options, dependencies) { if (dependencies == null) { dependencies = {}; } this.onEnvelope = bind(this.onEnvelope, this); this.child_process = dependencies.child_process; if (this.child_process == null) { this.child_process = require('child_process'); } Function.__super__.constructor.apply(this, arguments); } Function.prototype.onEnvelope = function(envelope, callback) { var child; child = this.child_process.fork(path.join(__dirname, './function-worker-runner.js')); child.send(envelope); child.on('message', (function(_this) { return function(message) { if (_this.childDone) { return; } if (message.type === 'error') { _this.childDone = true; child.kill('SIGKILL'); callback(new Error(message.error)); return; } if (message.type === 'ready') { setTimeout(function() { if (_this.childDone) { return; } _this.childDone = true; child.kill('SIGKILL'); return callback(new Error('Function took too long')); }, 60000); return; } if (message.type === 'envelope') { _this.childDone = true; child.kill('SIGKILL'); envelope = message.envelope; callback(null, envelope.message); } }; })(this)); return child; }; return Function; })(CallbackComponent); module.exports = Function; }).call(this); //# sourceMappingURL=function.js.map