forked from cujojs/when
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master'
Conflicts: when.js
- Loading branch information
Showing
61 changed files
with
3,056 additions
and
593 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
.npmignore | ||
.idea/ | ||
experiments/ | ||
node_modules/ | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ node_modules/ | |
.git/ | ||
.idea/ | ||
experiments/ | ||
test/monitor |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.idea/ | ||
.idea/.name | ||
.gitignore/ | ||
test/ | ||
projectFilesBackup/ | ||
experiments/ | ||
docs | ||
jsdoc | ||
jsdoc3 | ||
.npmignore | ||
.gitmodules | ||
.travis.yml | ||
*.globalized.js |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!doctype html> | ||
<html lang="en-US"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title></title> | ||
<script type="text/javascript" src="../node_modules/curl/src/curl.js"></script> | ||
<script type="text/javascript"> | ||
curl.config({ | ||
packages: { | ||
when: { location: '..', main: 'when' }, | ||
benchmark: { | ||
location: '../node_modules/benchmark', main: 'benchmark' | ||
} | ||
} | ||
}); | ||
|
||
curl(['./promise.js']); | ||
</script> | ||
</head> | ||
<body> | ||
|
||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** @license MIT License (c) copyright 2010-2013 original author or authors */ | ||
|
||
/** | ||
* Licensed under the MIT License at: | ||
* http://www.opensource.org/licenses/mit-license.php | ||
* | ||
* @author: Brian Cavalier | ||
* @author: John Hann | ||
*/ | ||
|
||
(function(define) { 'use strict'; | ||
define(function(require) { | ||
|
||
var when, tests, run; | ||
|
||
when = require('../when'); | ||
run = require('./run'); | ||
|
||
tests = [ | ||
{ name: 'map 100', fn: map(100), defer: true }, | ||
{ name: 'map 1k', fn: map(1e3), defer: true } | ||
]; | ||
|
||
run(tests); | ||
|
||
// | ||
// Benchmark tests | ||
// | ||
|
||
function map(n) { | ||
return function(deferred) { | ||
|
||
var input = []; | ||
for(var i = 0; i < n; i++) { | ||
input.push(when(i)); | ||
} | ||
|
||
when.map(input, addOne).then(function() { | ||
deferred.resolve(); | ||
}); | ||
|
||
}; | ||
} | ||
|
||
// | ||
// Promise helpers | ||
// | ||
|
||
function addOne(x) { | ||
return x + 1; | ||
} | ||
|
||
}); | ||
}(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(require); })); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
/** @license MIT License (c) copyright 2010-2013 original author or authors */ | ||
|
||
/** | ||
* Licensed under the MIT License at: | ||
* http://www.opensource.org/licenses/mit-license.php | ||
* | ||
* @author: Brian Cavalier | ||
* @author: John Hann | ||
*/ | ||
|
||
(function(define) { 'use strict'; | ||
define(function(require) { | ||
/*global setImmediate,process*/ | ||
|
||
var when, tests, run, ok; | ||
|
||
when = require('../when'); | ||
run = require('./run'); | ||
ok = 0; | ||
|
||
tests = [ | ||
{ name: 'create pending', fn: createPending }, | ||
{ name: 'resolve promise', fn: resolvePromise, defer: true }, | ||
{ name: 'setImmediate', fn: viaSetImmediate, defer: true, | ||
condition: checkSetImmediate }, | ||
{ name: 'process.nextTick', fn: viaProcessNextTick, defer: true, | ||
condition: checkProcessNextTick }, | ||
{ name: 'setTimeout', fn: viaSetTimeout, defer: true }, | ||
{ name: 'reject promise', fn: rejectPromise, defer: true }, | ||
{ name: 'reject then resolve', fn: rejectThenResolve, defer: true }, | ||
{ name: 'resolve chain 100', fn: resolveChain(100), defer: true }, | ||
{ name: 'resolve chain 1k', fn: resolveChain(1e3), defer: true }, | ||
{ name: 'sparse resolve chain 1k', fn: resolveChainSparse(1e3), defer: true }, | ||
{ name: 'reject chain 100', fn: rejectChain(100), defer: true }, | ||
{ name: 'reject chain 1k', fn: rejectChain(1e3), defer: true }, | ||
{ name: 'sparse reject chain 1k', fn: rejectChainSparse(1e3), defer: true }, | ||
// These 10k tests seem to cause significant garbage collection | ||
// hits that skew results of other tests. So, they are disabled | ||
// for now, but we need to figure out how to reduce the memory | ||
// thrashing these cause. | ||
// Leaving one enabled for now. | ||
{ name: 'resolve chain 10k', fn: resolveChain(1e4), defer: true } | ||
// { name: 'sparse resolve chain 10k', fn: resolveChainSparse(1e4), defer: true }, | ||
// { name: 'reject chain 10k', fn: rejectChain(1e4), defer: true }, | ||
// { name: 'sparse reject chain 10k', fn: rejectChainSparse(1e4), defer: true } | ||
]; | ||
|
||
run(tests); | ||
|
||
// | ||
// Benchmark tests | ||
// | ||
|
||
function createPending() { | ||
when.promise(pendingForever); | ||
} | ||
|
||
function resolvePromise(deferred) { | ||
when.promise(resolve).then(function() { | ||
deferred.resolve(); | ||
}); | ||
} | ||
|
||
function rejectPromise(deferred) { | ||
when.promise(reject).then(null, function() { | ||
deferred.resolve(); | ||
}); | ||
} | ||
|
||
function rejectThenResolve(deferred) { | ||
when.promise(reject).then(null, identity).then(function() { | ||
deferred.resolve(); | ||
}); | ||
} | ||
|
||
function viaSetTimeout(deferred) { | ||
setTimeout(function() { | ||
deferred.resolve(); | ||
}, 0); | ||
} | ||
|
||
function viaSetImmediate(deferred) { | ||
setImmediate(function() { | ||
deferred.resolve(); | ||
}); | ||
} | ||
|
||
function viaProcessNextTick(deferred) { | ||
process.nextTick(function() { | ||
deferred.resolve(); | ||
}); | ||
} | ||
|
||
function resolveChain(n) { | ||
return function(deferred) { | ||
var p = when.resolve({}), i = 0; | ||
for(;i < n; i++) { | ||
p = p.then(identity); | ||
} | ||
|
||
p.then(function() { | ||
deferred.resolve(); | ||
}); | ||
}; | ||
} | ||
|
||
function resolveChainSparse(n) { | ||
return function(deferred) { | ||
var p = when.resolve({}), i = 1; | ||
for(;i < n; i++) { | ||
p = p.then(null); | ||
} | ||
|
||
p.then(identity).then(function() { | ||
deferred.resolve(); | ||
}); | ||
}; | ||
} | ||
|
||
function rejectChain(n) { | ||
return function(deferred) { | ||
var p = when.reject({}), i = 0; | ||
for(;i < n; i++) { | ||
p = p.then(null, rethrow); | ||
} | ||
|
||
p.then(null, function() { | ||
deferred.resolve(); | ||
}); | ||
}; | ||
} | ||
|
||
function rejectChainSparse(n) { | ||
return function(deferred) { | ||
var p = when.reject({}), i = 1; | ||
for(;i < n; i++) { | ||
p = p.then(null, rethrow); | ||
} | ||
|
||
p.then(null, identity).then(function() { | ||
deferred.resolve(); | ||
}); | ||
}; | ||
} | ||
|
||
// | ||
// Promise helpers | ||
// | ||
|
||
function pendingForever() {} | ||
|
||
function resolve(r) { | ||
r(); | ||
} | ||
|
||
function reject(_, r) { | ||
r(); | ||
} | ||
|
||
function identity(x) { | ||
return x; | ||
} | ||
|
||
function rethrow(e) { | ||
throw e; | ||
} | ||
|
||
function checkSetImmediate() { | ||
return typeof setImmediate === 'function' | ||
? ok : 'setImmediate() not available'; | ||
} | ||
|
||
function checkProcessNextTick() { | ||
return typeof process !== 'undefined' | ||
&& typeof process.nextTick === 'function' | ||
? ok : 'process.nextTick() not available'; | ||
} | ||
|
||
}); | ||
}(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(require); })); |
Oops, something went wrong.