This repository has been archived by the owner on Jun 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
66 lines (55 loc) · 1.4 KB
/
index.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
require("source-map-support/register");
var Queue = require("../").default;
var assert = require("assert");
var logs = require("./logs");
var outs = [];
var oldNode = parseFloat(process.version.slice(1)) < 7.6;
// instantiate with a first task.
var queue = new Queue(function (next) {
outs.push("Hello, World!");
next();
});
// push a new task.
queue.push(function (next) {
setTimeout(function () {
outs.push("Hi, Ayon!");
next();
}, 200);
});
// push a new task and don't pass the `next`.
queue.push(function () {
assert.deepStrictEqual(outs, ["Hello, World!", "Hi, Ayon!"]);
outs.pop();
});
// push another function.
queue.push(function (next) {
assert.deepEqual(outs, ["Hello, World!"]);
logs.push("AAA");
next();
});
// push a function that will return a queue
queue.push(function () {
return require("./test-promise");
});
queue.push(function () {
return require("./test-handle-error");
});
queue.push(function () {
if (!oldNode) {
return require("./test-async-function");
}
});
var res;
setTimeout(() => {
queue.push(function () {
if (!oldNode)
assert.deepEqual(logs, ["AAA", "BBB", "CCC", "DDD", "EEE"]);
else
assert.deepEqual(logs, ["AAA", "BBB", "CCC", "DDD"]);
res = "#### OK ####";
});
}, 300);
setTimeout(() => {
assert.equal(res, "#### OK ####");
console.log(res);
}, 400);