We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 003360b commit 94fe3a3Copy full SHA for 94fe3a3
1 file changed
JavaScript/b-errors.js
@@ -0,0 +1,45 @@
1
+'use strict';
2
+
3
+// Implementation
4
5
+const adder = (value) => {
6
+ const add = (a) => {
7
+ value += a;
8
+ if (value >= add.maxValue) {
9
+ setImmediate(() => {
10
+ add.maxEvent(new Error('max value reached'), value);
11
+ });
12
+ }
13
+ return add;
14
+ };
15
+ // callback-last
16
+ add.max = (max, event) => {
17
+ add.maxValue = max;
18
+ add.maxEvent = event;
19
20
21
22
+};
23
24
+// Usage
25
26
+// error-first
27
+const maxReached = (err, value) => {
28
+ if (err) {
29
+ console.log('value: ' + value);
30
+ throw err;
31
32
33
34
+try {
35
+ const a1 = adder(10).max(100, maxReached)(-5);
36
+ a1(25);
37
+ a1(50);
38
+ a1(75);
39
+ a1(100);
40
+ a1(-200)(50)(30);
41
+} catch (e) {
42
+ console.log('Never');
43
+}
44
45
+console.log('end');
0 commit comments