UNPKG

will

Version:

Flexible futures

50 lines (39 loc) 1.24 kB
// Generated by CoffeeScript 1.6.3 (function() { var Future, Promise, __hasProp = {}.hasOwnProperty, __extends = 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; }; Future = require('./future'); module.exports = Promise = (function(_super) { var allowed, name; __extends(Promise, _super); allowed = { getStateName: true, once: true }; function Promise(deferral) { this._apply = function(method, args) { var result; if (!allowed[method]) { return; } result = deferral[method].apply(deferral, args); if (result === deferral) { result = this; } return result; }; } Promise.prototype.promise = function() { return this; }; for (name in allowed) { Promise.prototype[name] = (function(name) { return function() { return this._apply(name, arguments); }; })(name); } return Promise; })(Future); }).call(this);