File tree Expand file tree Collapse file tree 1 file changed +15
-9
lines changed Expand file tree Collapse file tree 1 file changed +15
-9
lines changed Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
3
class Future {
4
+ #executor;
5
+
4
6
constructor ( executor ) {
5
- this . executor = executor ;
7
+ this . # executor = executor ;
6
8
}
7
9
8
10
static of ( value ) {
@@ -35,16 +37,20 @@ class Future {
35
37
}
36
38
37
39
fork ( successed , failed ) {
38
- this . executor ( successed , failed ) ;
40
+ this . # executor( successed , failed ) ;
39
41
}
40
42
41
- promise ( ) {
42
- return new Promise ( ( resolve , reject ) => {
43
- this . fork (
44
- ( value ) => resolve ( value ) ,
45
- ( error ) => reject ( error ) ,
46
- ) ;
47
- } ) ;
43
+ toPromise ( ) {
44
+ const { promise, resolve, reject } = Promise . withResolvers ( ) ;
45
+ this . fork ( resolve , reject ) ;
46
+ return promise ;
47
+ }
48
+
49
+ toThenable ( ) {
50
+ const then = ( resolve , reject ) => {
51
+ this . fork ( resolve , reject ) ;
52
+ } ;
53
+ return { then } ;
48
54
}
49
55
}
50
56
You can’t perform that action at this time.
0 commit comments