This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var most = require('most'); | |
module.exports = function() { | |
var ws = new WebSocket('ws://localhost:8080'); | |
var s = most.create(function(add, end, error) { | |
ws.addEventListener('open', onOpen); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = captureDefines; | |
function captureDefines (amdEval) { | |
return function (load) { | |
var result, isAnon, _define; | |
result = { named: [] }; | |
_define = function captureDefine () { | |
var args, def; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use native or try any of these promise impls. | |
// They all behave the same. | |
//var Promise = require('when').Promise; | |
//var Promise = require('rsvp').Promise; | |
//var Promise = require('bluebird'); | |
// Here are 2 promises, p1 and p2. p2 always *actually* finishes | |
// first, since p1 finishes in 1 millisecond, and p2 is already | |
// finished when created |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function logWinner (p1, p2) { | |
Promise.race([p1, p2]).then(console.log.bind(console)); | |
} | |
var p1 = new Promise(function(resolve) { | |
setTimeout(function() { resolve('p1'); }, 20); | |
}); | |
var p2 = new Promise(function(resolve) { | |
setTimeout(function() { resolve('p2'); }, 10); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var most = require('most'); | |
var connect = { then: function(f) { f(); } }; | |
function getResource() { | |
return most.fromPromise(connect).flatMap(function() { | |
return getSnapshot().flatMap(function() { | |
return getUpdates(); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @license MIT License (c) copyright 2010-2014 original author or authors */ | |
/** @author Brian Cavalier */ | |
/** @author John Hann */ | |
(function(define) { 'use strict'; | |
define(function(require) { | |
var setTimer = require('../env').setTimer; | |
return function unhandledRejection(Promise) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @license MIT License (c) copyright 2010-2014 original author or authors */ | |
/** | |
* Licensed under the MIT License at: | |
* http://www.opensource.org/licenses/mit-license.php | |
* @author: Brian Cavalier | |
*/ | |
var when = require('when'); | |
function Transaction(runTransaction) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var when = require('../../../when'); | |
var a = []; | |
for(var i=0; i<1000000; ++i) { | |
a[i] = when.resolve(i); | |
} | |
var start = Date.now(); | |
when.map(a, function(x) { | |
return add(x, 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var when = require('../../../when'); | |
var a = []; | |
for(var i=0; i<1000000; ++i) { | |
a[i] = when.resolve(i); | |
} | |
var start = Date.now(); | |
when.reduce(a, add, 0).done(function(r) { | |
//when.reduceRight(a, add, 0).done(function(r) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Dropping sparse array support makes this code much simpler | |
function reduce(promises, f) { | |
var hasArg = arguments.length > 2; | |
if((promises.length>>>0) === 0) { | |
return hasArg ? when.promise(arguments[2]) : when.reject(new TypeError('Cannot reduce empty array with no initial value')); | |
} | |
return hasArg ? runReduce(0, promises, f, arguments[2]) | |
: runReduce(1, promises, f, promises[0]); | |
} |