Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

complex continuation with livescript and continuation.js

View continuation.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
/* Generated by Continuation.js v0.0.5 */
(function () {
var identity, sum, transform_array, ranges, i$, len$, range;
identity = function (el, callback) {
var delayed;
delayed = function () {
return callback(el);
};
return setTimeout(delayed, 100);
};
sum = function (el, number, callback) {
var delayed;
delayed = function () {
return callback(el + number);
};
return setTimeout(delayed, 100);
};
transform_array = function (list, callback) {
var new_list, i$, len$, n;
new_list = [];
i$ = 0, len$ = list.length;
function loop_0(loop_0_cont) {
if (i$ < len$) {
n = list[i$];
identity(n, function () {
n = arguments[0];
sum(n, 10, function () {
n = arguments[0];
identity(n, function () {
n = arguments[0];
sum(n, 10, function () {
n = arguments[0];
n = n + 100;
(function (cont) {
if (n % 3 === 0) {
identity(n, function () {
n = arguments[0];
sum(n, 10, function () {
n = arguments[0];
identity(n, function () {
n = arguments[0];
sum(n, 10, function () {
n = arguments[0];
identity(n, function () {
n = arguments[0];
sum(n, 10, function () {
n = arguments[0];
if (n > 15) {
new_list.push(n);
}
cont();
});
});
});
});
});
});
} else {
cont();
}
}(function (err) {
if (err !== undefined)
return cont(err);
++i$;
loop_0(loop_0_cont);
}));
});
});
});
});
} else {
loop_0_cont();
}
}
loop_0(function () {
return callback(new_list);
});
};
ranges = [
[
1,
2,
3,
4,
5,
6,
7,
8,
9,
10
],
[
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20
],
[
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30
]
];
i$ = 0, len$ = ranges.length;
function loop_1(loop_1_cont) {
if (i$ < len$) {
range = ranges[i$];
transform_array(range, function () {
range = arguments[0];
console.log(range);
++i$;
loop_1(loop_1_cont);
});
} else {
loop_1_cont();
}
}
loop_1(function () {
});
}.call(this));
View continuation.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
identity = (el,callback) ->
delayed = -> callback(el)
setTimeout delayed,100
sum = (el,number,callback) ->
delayed = -> callback(el+number)
setTimeout delayed,100
 
 
transform_array= (list,callback) ->
new_list=[]
for n in list
identity(n,cont(n))
sum(n,10,cont(n))
identity(n,cont(n))
sum(n,10,cont(n))
n=n+100
if n % 3== 0
identity(n,cont(n))
sum(n,10,cont(n))
identity(n,cont(n))
sum(n,10,cont(n))
identity(n,cont(n))
sum(n,10,cont(n))
# cont(x) is the continuation that put the value of cb function inside x
if n > 15
new_list.push(n)
callback(new_list)
ranges=[[1 to 10],[10 to 20],[20 to 30]]
 
for range in ranges
transform_array(range,cont(range))
console.log range
View continuation.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
function d(a) {
e < h ? (i = j[e], l(i, function(c) {
i = c;
console.log(i);
++e;
d(a)
})) : a()
}
var m, n, l, j, e, h, i;
m = function(a, c) {
setTimeout(function() {
return c(a)
}, 100)
};
n = function(a, c, f) {
setTimeout(function() {
return f(a + c)
}, 100)
};
l = function(a, c) {
function f(c) {
g < p ? (b = a[g], m(b, function(a) {
b = a;
n(b, 10, function(a) {
b = a;
m(b, function(a) {
b = a;
n(b, 10, function(a) {
b = a;
b += 100;
0 === b % 3 ? m(b, function(a) {
b = a;
n(b, 10, function(a) {
b = a;
m(b, function(a) {
b = a;
n(b, 10, function(a) {
b = a;
m(b, function(a) {
b = a;
n(b, 10, function(a) {
b = a;
15 < b && k.push(b);
++g;
f(c)
})
})
})
})
})
}) : (++g, f(c))
})
})
})
})) : c()
}
var k, g, p, b;
k = [];
g = 0;
p = a.length;
f(function() {
return c(k)
})
};
j = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20], [20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]];
e = 0;
h = j.length;
d(function() {
});
View continuation.js
1 2 3
[ 153, 156, 159 ]
[ 162, 165, 168 ]
[ 171, 174, 177, 180 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.