-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
57 lines (50 loc) · 1.12 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
/*jslint node: true */
"use strict";
/**
* Format and show the promise value on the console.
*/
exports.show = function (v) {
console.log(JSON.stringify(v, null, 4));
return v;
};
/**
* Replace the promise value with nothing.
*/
exports.ignore = function () {
return null;
};
/**
* Do nothing.
*/
exports.nop = function (v) {
return v;
};
/**
* Create a function pair that can capture and re-introduce a promise value.
*/
exports.createCapture = function () {
var captured = false,
value = null;
return {
/*
* store the promise value for later retrieval. Can only be used once.
*/
assign: function (v) {
if (captured) {
throw new Error("Capture is already assigned.");
}
value = v;
captured = true;
return v;
},
/*
* emit the promise value. Can only be used after assignment.
*/
use: function () {
if (!captured) {
throw new Error("Capture is not assigned.");
}
return value;
}
};
};