Comparing version 0.6.4 to 0.6.5
@@ -123,3 +123,23 @@ "use strict"; | ||
} else if (this.error) { | ||
throw this.error; | ||
// Link the stack traces up | ||
var stack = {}, error = this.error instanceof Object ? this.error : new Error(this.error); | ||
var longError = Object.create(error); | ||
Error.captureStackTrace(stack, Future.prototype.get); | ||
Object.defineProperty(longError, 'stack', { | ||
get: function() { | ||
var baseStack = error.stack; | ||
if (baseStack) { | ||
baseStack = baseStack.split('\n'); | ||
return [baseStack[0]] | ||
.concat(stack.stack.split('\n').slice(1)) | ||
.concat(' - - - - -') | ||
.concat(baseStack.slice(1)) | ||
.join('\n'); | ||
} else { | ||
return stack.stack; | ||
} | ||
}, | ||
enumerable: true, | ||
}); | ||
throw longError; | ||
} else { | ||
@@ -145,3 +165,8 @@ return this.value; | ||
try { | ||
callbacks[ii](undefined, value); | ||
var ref = callbacks[ii]; | ||
if (ref[1]) { | ||
ref[1](value); | ||
} else { | ||
ref[0](undefined, value); | ||
} | ||
} catch(ex) { | ||
@@ -172,3 +197,8 @@ console.log(String(ex.stack || ex.message || ex)); | ||
try { | ||
callbacks[ii](error); | ||
var ref = callbacks[ii]; | ||
if (ref[1]) { | ||
ref[0].throw(error); | ||
} else { | ||
ref[0](error); | ||
} | ||
} catch(ex) { | ||
@@ -183,2 +213,16 @@ console.log(ex.stack || ex); | ||
/** | ||
* "detach" this future. Basically this is useful if you want to run a task in a future, you | ||
* aren't interested in its return value, but if it throws you don't want the exception to be | ||
* lost. If this fiber throws, an exception will be thrown to the event loop and node will | ||
* probably fall down. | ||
*/ | ||
detach: function() { | ||
this.resolve(function(err) { | ||
if (err) { | ||
throw err; | ||
} | ||
}); | ||
}, | ||
/** | ||
* Returns whether or not this future has resolved yet. | ||
@@ -205,8 +249,21 @@ */ | ||
* Waits for this future to resolve and then invokes a callback. | ||
* | ||
* If two arguments are passed, the first argument is a future which will be thrown to in the case | ||
* of error, and the second is a function(val){} callback. | ||
* | ||
* If only one argument is passed it is a standard function(err, val){} callback. | ||
*/ | ||
resolve: function(cb) { | ||
resolve: function(arg1, arg2) { | ||
if (this.resolved) { | ||
cb(this.error, this.value); | ||
if (arg2) { | ||
if (this.error) { | ||
arg1.throw(this.error); | ||
} else { | ||
arg2(this.value); | ||
} | ||
} else { | ||
arg1(this.error, this.value); | ||
} | ||
} else { | ||
(this.callbacks = this.callbacks || []).push(cb); | ||
(this.callbacks = this.callbacks || []).push([arg1, arg2]); | ||
} | ||
@@ -213,0 +270,0 @@ return this; |
{ | ||
"name": "fibers", | ||
"version": "0.6.4", | ||
"version": "0.6.5", | ||
"description": "Cooperative multi-tasking for Javascript; or, the closest thing to a thread you'll see in node", | ||
@@ -18,3 +18,3 @@ "keywords": [ | ||
}, | ||
"os": ["macos", "linux"], | ||
"os": ["darwin", "linux"], | ||
"engines": { | ||
@@ -21,0 +21,0 @@ "node": ">=0.5.2" |
require('fibers'); | ||
var fibers = []; | ||
for (var jj = 0; jj < 10; ++jj) { | ||
var fibers = []; | ||
for (var ii = 0; ii < 200; ++ii) { | ||
@@ -6,0 +6,0 @@ var fn = Fiber(function() { |
// gh-10 | ||
require('fibers'); | ||
var title = process.title; | ||
Fiber(function() { | ||
process.title = 'pass'; | ||
}).run(); | ||
// sunos process.title doesn't work, regardless of fibers | ||
console.log(process.platform === 'sunos' ? 'pass' : process.title); | ||
console.log(process.title === 'pass' || process.title === title ? 'pass' : 'fail'); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
95241
34
515
2