@@ -43,7 +43,7 @@ async function Bar({children}) {
43
43
}
44
44
45
45
async function ThirdPartyComponent ( ) {
46
- return delay ( 'hello from a 3rd party' , 30 ) ;
46
+ return await delay ( 'hello from a 3rd party' , 30 ) ;
47
47
}
48
48
49
49
let cachedThirdPartyStream ;
@@ -52,16 +52,35 @@ let cachedThirdPartyStream;
52
52
// That way it gets the owner from the call to createFromNodeStream.
53
53
const thirdPartyComponent = < ThirdPartyComponent /> ;
54
54
55
- function fetchThirdParty ( noCache ) {
55
+ function simulateFetch ( cb , latencyMs ) {
56
+ return new Promise ( resolve => {
57
+ // Request latency
58
+ setTimeout ( ( ) => {
59
+ const result = cb ( ) ;
60
+ // Response latency
61
+ setTimeout ( ( ) => {
62
+ resolve ( result ) ;
63
+ } , latencyMs ) ;
64
+ } , latencyMs ) ;
65
+ } ) ;
66
+ }
67
+
68
+ async function fetchThirdParty ( noCache ) {
56
69
// We're using the Web Streams APIs for tee'ing convenience.
57
- const stream =
58
- cachedThirdPartyStream && ! noCache
59
- ? cachedThirdPartyStream
60
- : renderToReadableStream (
70
+ let stream ;
71
+ if ( cachedThirdPartyStream && ! noCache ) {
72
+ stream = cachedThirdPartyStream ;
73
+ } else {
74
+ stream = await simulateFetch (
75
+ ( ) =>
76
+ renderToReadableStream (
61
77
thirdPartyComponent ,
62
78
{ } ,
63
79
{ environmentName : 'third-party' }
64
- ) ;
80
+ ) ,
81
+ 25
82
+ ) ;
83
+ }
65
84
66
85
const [ stream1 , stream2 ] = stream . tee ( ) ;
67
86
cachedThirdPartyStream = stream1 ;
0 commit comments