How to use the promise.Promise function in promise

To help you get started, we’ve selected a few promise examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mozilla / bespinclient / plugins / boot / bespin / plugins.js View on Github external
var ext = this.getExtensionByKey("factory", factoryName);
        if (ext === undefined) {
            throw new Error('When creating object "' + name +
                '", there is no factory called "' + factoryName +
                '" available."');
        }

        // If this is a child catalog and the extension is shared, then
        // as the master/parent catalog to create the object.
        if (this.parent && this.shareExtension(ext)) {
            return this.instancesLoadPromises[name] = this.parent.createObject(name);
        }

        // Otherwise create a new loading promise (which is returned at the
        // end of the function) and create the instance.
        var pr = this.instancesLoadPromises[name] = new Promise();

        var factoryArguments = descriptor.arguments || [];
        var argumentPromises = [];
        if (descriptor.objects) {
            var objects = descriptor.objects;
            for (var key in objects) {
                var objectName = objects[key];
                var ropr = this.createObject(objectName);
                argumentPromises.push(ropr);
                // key is changing, so we need to hang onto the
                // current value
                ropr.location = key;
                ropr.then(function(obj) {
                    _setPath(factoryArguments, ropr.location, obj);
                });
            }
github publiclab / spectral-workbench / public / lib / bespin-0.9a2 / plugins / boot / bespin / plugins.js View on Github external
var ext = this.getExtensionByKey("factory", factoryName);
        if (ext === undefined) {
            throw new Error('When creating object "' + name +
                '", there is no factory called "' + factoryName +
                '" available."');
        }

        // If this is a child catalog and the extension is shared, then
        // as the master/parent catalog to create the object.
        if (this.parent && this.shareExtension(ext)) {
            return this.instancesLoadPromises[name] = this.parent.createObject(name);
        }

        // Otherwise create a new loading promise (which is returned at the
        // end of the function) and create the instance.
        var pr = this.instancesLoadPromises[name] = new Promise();

        var factoryArguments = descriptor.arguments || [];
        var argumentPromises = [];
        if (descriptor.objects) {
            var objects = descriptor.objects;
            for (var key in objects) {
                var objectName = objects[key];
                var ropr = this.createObject(objectName);
                argumentPromises.push(ropr);
                // key is changing, so we need to hang onto the
                // current value
                ropr.location = key;
                ropr.then(function(obj) {
                    _setPath(factoryArguments, ropr.location, obj);
                });
            }
github kriskowal / narwhal-lib / tests / promise.js View on Github external
exports["test split then"] = function () {

    var p = promiseModule.Promise();
	var p2 = p.then(
	  function () {
	    return '1';
	  })
	 .then(
	  function () {
	    return '2';
	  });
    var ok,ok2;
 
	promiseModule.when(p, function(value) {
		print("p " + value);
	    ok = value;
	  });
	promiseModule.when(p2, function(value) {
	    ok2 = value;
github plasmidhq / plasmid / static / jsonsca.js View on Github external
exports.stringify = function(data) {
        var pack_promise = exports.pack(data);
        var stringify_promise = new Promise();
        pack_promise.then(function(packed) {
            stringify_promise.ok(JSON.stringify(packed));
        });
        return stringify_promise;
    };
github publiclab / spectral-workbench / public / lib / bespin-0.9a2 / plugins / boot / bespin / plugins.js View on Github external
load: function(callback, property, catalog) {
        catalog = catalog || exports.catalog;
        var promise = new Promise();

        var onComplete = function(func) {
            if (callback) {
                callback(func);
            }
            promise.resolve(func);
        };

        var pointerVal = this[property || 'pointer'];
        if (util.isFunction(pointerVal)) {
            onComplete(pointerVal);
            return promise;
        }

        var pointerObj = _splitPointer(this.pluginName, pointerVal);
github mozilla / bespinclient / plugins / boot / bespin / plugins.js View on Github external
loadMetadataFromURL: function(url, type) {
        var pr = new Promise();
        proxy.xhr('GET', url, true).then(function(response) {
            this.registerMetadata(JSON.parse(response));
            pr.resolve();
        }.bind(this), function(err) {
            pr.reject(err);
        });

        return pr;
    },
github mozilla / bespinclient / plugins / boot / bespin / plugins.js View on Github external
loadObjectForPropertyPath: function(path, context) {
        var promise = new Promise();
        var parts = /^([^:]+):([^#]+)#(.*)$/.exec(path);
        if (parts === null) {
            throw new Error("loadObjectForPropertyPath: malformed path: '" +
                path + "'");
        }

        var pluginName = parts[1];
        if (pluginName === "") {
            if (util.none(context)) {
                throw new Error("loadObjectForPropertyPath: no plugin name " +
                    "supplied and no context is present");
            }

            pluginName = context;
        }
github publiclab / spectral-workbench / public / lib / bespin-0.9a2 / plugins / boot / bespin / proxy.js View on Github external
exports.xhr = function(method, url, async, beforeSendCallback) {
    var pr = new Promise();

    if (!bespin.proxy || !bespin.proxy.xhr) {
        var req = new XMLHttpRequest();
        req.onreadystatechange = function() {
            if (req.readyState !== 4) {
                return;
            }

            var status = req.status;
            if (status !== 0 && status !== 200) {
                var error = new Error(req.responseText + ' (Status ' + req.status + ")");
                error.xhr = req;
                pr.reject(error);
                return;
            }
github publiclab / spectral-workbench / public / lib / bespin-0.9a2 / plugins / boot / bespin / plugins.js View on Github external
loadObjectForPropertyPath: function(path, context) {
        var promise = new Promise();
        var parts = /^([^:]+):([^#]+)#(.*)$/.exec(path);
        if (parts === null) {
            throw new Error("loadObjectForPropertyPath: malformed path: '" +
                path + "'");
        }

        var pluginName = parts[1];
        if (pluginName === "") {
            if (util.none(context)) {
                throw new Error("loadObjectForPropertyPath: no plugin name " +
                    "supplied and no context is present");
            }

            pluginName = context;
        }
github plasmidhq / plasmid / static / jsonsca.js View on Github external
exports.pack = function(input, reftracker) {
        var promise = new Promise();
        var t = typeof input;
        if (typeof reftracker === 'undefined') {
            var reftracker = new exports._ReferenceTracker();
        }
        var reference = reftracker.reference(input);
        if (reference && reference.ref) {
            promise.ok({'reference': reference.ref});
        } else if (t === 'string' || t === 'number' || t === 'boolean') {
            promise.ok(input);
        } else if (t === 'undefined') {
            promise.ok({'undefined': true});
        } else if (input === null) {
            promise.ok({'null': true});
        } else if (input instanceof Date) {
            promise.ok({'date': input.getTime()});
        } else if (input instanceof RegExp) {