File tree Expand file tree Collapse file tree 3 files changed +11
-0
lines changed Expand file tree Collapse file tree 3 files changed +11
-0
lines changed Original file line number Diff line number Diff line change 3
3
const asyncResult = ( ) => ( {
4
4
value : undefined ,
5
5
onDone : null ,
6
+
6
7
done ( callback ) {
7
8
this . onDone = callback ;
8
9
return this ;
9
10
} ,
11
+
10
12
resolve ( value ) {
11
13
this . value = value ;
12
14
if ( this . onDone ) this . onDone ( value ) ;
Original file line number Diff line number Diff line change @@ -4,11 +4,13 @@ const asyncResult = () => ({
4
4
value : undefined ,
5
5
onDone : null ,
6
6
resolved : false ,
7
+
7
8
done ( callback ) {
8
9
this . onDone = callback ;
9
10
if ( this . resolved ) callback ( this . value ) ;
10
11
return this ;
11
12
} ,
13
+
12
14
resolve ( value ) {
13
15
this . value = value ;
14
16
this . resolved = true ;
Original file line number Diff line number Diff line change @@ -9,31 +9,38 @@ const deferred = () => ({
9
9
onDone : null ,
10
10
onFail : null ,
11
11
status : DEFERRED_PENDING ,
12
+
12
13
isPending ( ) {
13
14
return this . status === DEFERRED_PENDING ;
14
15
} ,
16
+
15
17
isResolved ( ) {
16
18
return this . status === DEFERRED_RESOLVED ;
17
19
} ,
20
+
18
21
isRejected ( ) {
19
22
return this . status === DEFERRED_REJECTED ;
20
23
} ,
24
+
21
25
done ( callback ) {
22
26
this . onDone = callback ;
23
27
if ( this . isResolved ( ) ) callback ( this . value ) ;
24
28
return this ;
25
29
} ,
30
+
26
31
fail ( callback ) {
27
32
this . onFail = callback ;
28
33
if ( this . isRejected ( ) ) callback ( this . value ) ;
29
34
return this ;
30
35
} ,
36
+
31
37
resolve ( value ) {
32
38
this . value = value ;
33
39
this . status = DEFERRED_RESOLVED ;
34
40
if ( this . onDone ) this . onDone ( value ) ;
35
41
return this ;
36
42
} ,
43
+
37
44
reject ( value ) {
38
45
this . value = value ;
39
46
this . status = DEFERRED_REJECTED ;
You can’t perform that action at this time.
0 commit comments