| 354 | } |
| 355 | |
| 356 | function readText(text) { |
| 357 | const record = textCache.get(text); |
| 358 | if (record !== undefined) { |
| 359 | switch (record.status) { |
| 360 | case 'pending': |
| 361 | throw record.value; |
| 362 | case 'rejected': |
| 363 | throw record.value; |
| 364 | case 'resolved': |
| 365 | return record.value; |
| 366 | } |
| 367 | } else { |
| 368 | const thenable = { |
| 369 | pings: [], |
| 370 | then(resolve) { |
| 371 | if (newRecord.status === 'pending') { |
| 372 | thenable.pings.push(resolve); |
| 373 | } else { |
| 374 | Promise.resolve().then(() => resolve(newRecord.value)); |
| 375 | } |
| 376 | }, |
| 377 | }; |
| 378 | |
| 379 | const newRecord = { |
| 380 | status: 'pending', |
| 381 | value: thenable, |
| 382 | }; |
| 383 | textCache.set(text, newRecord); |
| 384 | |
| 385 | throw thenable; |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | function Text({text}) { |
| 390 | return text; |