@@ -43,7 +43,7 @@ async function Bar({children}) {
4343}
4444
4545async function ThirdPartyComponent ( ) {
46- return delay ( 'hello from a 3rd party' , 30 ) ;
46+ return await delay ( 'hello from a 3rd party' , 30 ) ;
4747}
4848
4949let cachedThirdPartyStream ;
@@ -52,16 +52,35 @@ let cachedThirdPartyStream;
5252// That way it gets the owner from the call to createFromNodeStream.
5353const thirdPartyComponent = < ThirdPartyComponent /> ;
5454
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 ) {
5669 // 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 (
6177 thirdPartyComponent ,
6278 { } ,
6379 { environmentName : 'third-party' }
64- ) ;
80+ ) ,
81+ 25
82+ ) ;
83+ }
6584
6685 const [ stream1 , stream2 ] = stream . tee ( ) ;
6786 cachedThirdPartyStream = stream1 ;
0 commit comments