Skip to content

Instantly share code, notes, and snippets.

@briancavalier briancavalier/1-cycle.js
Last active Aug 29, 2015

Embed
What would you like to do?
Upcoming when.js 3.2.0 will detect many arbitrary-length graph cycles (with no perf penalty. try it in the dev branch)
var when = require('when');
var d1 = when.defer();
var d2 = when.defer();
var d3 = when.defer();
d1.resolve(d2.promise);
d2.resolve(d3.promise);
d3.resolve(d1.promise);
// NOTE: No when/console/monitor and no .done() needed
Potentially unhandled rejection TypeError: Promise cycle
at promiseCycleHandler (/Users/brian/Projects/cujojs/when/lib/makePromise.js:669:31)
at getHandler (/Users/brian/Projects/cujojs/when/lib/makePromise.js:306:23)
at DeferredHandler.resolve (/Users/brian/Projects/cujojs/when/lib/makePromise.js:389:15)
at Deferred.resolve (/Users/brian/Projects/cujojs/when/when.js:134:36)
at Object.<anonymous> (/Users/brian/Projects/cujojs/when/experiments/cycle.js:9:4)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
require('when/monitor/console');
var when = require('when');
var d1 = when.defer();
var d2 = when.defer();
var d3 = when.defer();
d1.resolve(d2.promise);
d2.resolve(d3.promise);
d3.resolve(d1.promise);
// NOTE: Can still use monitor for better stack traces
// but still don't need .done()
[promises] Unhandled rejections: 1
TypeError: Promise cycle
from execution context:
at Object.<anonymous> (/Users/brian/Projects/cujojs/when/experiments/cycle.js:10:4)
from execution context:
at Object.<anonymous> (/Users/brian/Projects/cujojs/when/experiments/cycle.js:6:15)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.