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?
require('when/monitor/console');
var when = require('when');
// Creates a cycle p1 -> p2 -> p3 -> p4 -> p1
var p1 = when.promise(function(r1) {
var p2 = when.promise(function(r2) {
var p3 = when.promise(function(r3) {
var p4 = when.promise(function(r4) {
setTimeout(function() {
r4(p1); // Cycle! resolve p4 with p1
}, 100);
});
r3(p4);
});
r2(p3);
});
r1(p2);
});
TypeError: Promise cycle
at null._onTimeout (/Users/brian/Projects/cujojs/when/experiments/cycle.js:10:6)
[object Object]
at /Users/brian/Projects/cujojs/when/experiments/cycle.js:8:18
at /Users/brian/Projects/cujojs/when/experiments/cycle.js:7:17
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.