synchronize
Advanced tools
Comparing version
{ | ||
"name" : "synchronize", | ||
"main" : "./sync", | ||
"version" : "0.9.13", | ||
"version" : "0.9.14", | ||
"homepage" : "http://alexeypetrushin.github.com/synchronize", | ||
@@ -17,2 +17,5 @@ "repository": { | ||
}, | ||
"scripts" : { | ||
"test": "mocha -R spec test/*.js" | ||
}, | ||
"description" : "Turns asynchronous function into synchronous", | ||
@@ -19,0 +22,0 @@ "keywords" : ["Fibers", "Sync", "Async", "Control Flow"], |
@@ -16,7 +16,8 @@ synchronize.js allows You write asynchronous code as if it's synchronous. | ||
- [Andrew Tamura](https://github.com/andrewtamura) | ||
- [Jeff Wear](https://github.com/wearhere) | ||
Other resources: | ||
-[Patterns and anti-patterns using synchronize.js](https://mixmax.com/blog/node-fibers-using-synchronize-js) | ||
- [Patterns and anti-patterns using synchronize.js](https://mixmax.com/blog/node-fibers-using-synchronize-js) | ||
Copyright (c) Alexey Petrushin, http://petrush.in, released under the MIT license. | ||
Copyright (c) Alexey Petrushin, http://alex-craft.com, released under the MIT license. |
14
sync.js
@@ -27,2 +27,4 @@ /*jshint node: true, indent:2, loopfunc: true, asi: true, undef:true*/ | ||
var nextTick = global.setImmediate || process.nextTick || function(cb) { setTimeout(cb, 0) } | ||
// Sometimes `Fiber` needed outside of `sync`. | ||
@@ -105,3 +107,3 @@ sync.Fiber = Fiber | ||
// Wrapping in nextTick as a safe measure against not asynchronous usage. | ||
process.nextTick(function(){ | ||
nextTick(function(){ | ||
fiber._defered = false | ||
@@ -133,3 +135,3 @@ if(fiber._syncIsTerminated) return | ||
// Wrapping in nextTick as a safe measure against not asynchronous usage. | ||
process.nextTick(function(){ | ||
nextTick(function(){ | ||
if(fiber._syncIsTerminated) return | ||
@@ -174,3 +176,3 @@ // Error in any of parallel call will result in aborting all of the calls. | ||
var args = Array.prototype.slice.call(arguments, 1) | ||
process.nextTick(function(){ | ||
nextTick(function(){ | ||
fiber._defered = false | ||
@@ -211,3 +213,3 @@ if(fiber._syncIsTerminated) return | ||
var args = Array.prototype.slice.call(arguments, 1) | ||
process.nextTick(function(){ | ||
nextTick(function(){ | ||
if(fiber._syncIsTerminated) return | ||
@@ -256,3 +258,3 @@ | ||
if (!fiber._syncParallel.called) { | ||
process.nextTick(function(){ | ||
nextTick(function(){ | ||
// Return an empty array to represent that there were no results. | ||
@@ -273,3 +275,3 @@ if(!fiber._syncIsTerminated) fiber.run([]) | ||
// Prevent restart fiber | ||
if (fiber._started) return | ||
if (Fiber.current._started) return | ||
if (done) { | ||
@@ -276,0 +278,0 @@ var result |
202608
0.14%20
5.26%6185
0.02%23
4.55%