@@ -20,19 +20,19 @@ const Rejected = 2;
20
20
type PendingRecord = { |
21
21
status : 0 ,
22
22
value : Wakeable ,
23
- cache : Array < mixed > ,
23
+ cache : null ,
24
24
| } ;
25
25
26
26
type ResolvedRecord < T > = { |
27
27
status : 1 ,
28
28
value : T ,
29
- cache : Array < mixed > ,
29
+ cache : null | Array < mixed > ,
30
30
| } ;
31
31
32
32
type RejectedRecord = { |
33
33
status : 2 ,
34
34
value : mixed ,
35
- cache : Array < mixed > ,
35
+ cache : null ,
36
36
| } ;
37
37
38
38
type Record < T > = PendingRecord | ResolvedRecord < T > | RejectedRecord ;
@@ -41,7 +41,7 @@ function createRecordFromThenable<T>(thenable: Thenable<T>): Record<T> {
41
41
const record : Record < T > = {
42
42
status : Pending ,
43
43
value : thenable ,
44
- cache : [ ] ,
44
+ cache : null ,
45
45
} ;
46
46
thenable . then (
47
47
value => {
@@ -62,9 +62,9 @@ function createRecordFromThenable<T>(thenable: Thenable<T>): Record<T> {
62
62
return record ;
63
63
}
64
64
65
- function readRecordValue < T > (record: Record< T > ): T {
65
+ function readRecord < T > (record: Record< T > ): ResolvedRecord < T > {
66
66
if ( record . status === Resolved ) {
67
- return record . value ;
67
+ return record ;
68
68
} else {
69
69
throw record . value ;
70
70
}
@@ -114,7 +114,8 @@ export function readFile(
114
114
record = createRecordFromThenable ( thenable ) ;
115
115
map . set ( path , record ) ;
116
116
}
117
- const buffer : Buffer = readRecordValue ( record ) ;
117
+ const resolvedRecord = readRecord ( record ) ;
118
+ const buffer : Buffer = resolvedRecord . value ;
118
119
if ( ! options ) {
119
120
return buffer ;
120
121
}
@@ -136,7 +137,7 @@ export function readFile(
136
137
if ( typeof encoding !== 'string' ) {
137
138
return buffer ;
138
139
}
139
- const textCache = record . cache ;
140
+ const textCache = resolvedRecord . cache || ( resolvedRecord . cache = [ ] ) ;
140
141
for ( let i = 0 ; i < textCache . length ; i += 2 ) {
141
142
if ( textCache [ i ] === encoding ) {
142
143
return ( textCache [ i + 1 ] : any ) ;
0 commit comments