@@ -327,23 +327,90 @@ let main = async () => {
327327
328328 let batchSize = OS .cpus ()-> Array .length
329329
330- let compilationResults =
331- (await modules
332- -> chunkArray (batchSize )
333- -> Array .map (async arrExample => {
334- await arrExample
335- -> Array .map (async example => {
336- let id = example .id -> String .replaceAll ("." , "__" )
337- let rescriptCode = example -> getCodeBlocks
338- let jsCode = await compileTest (~id , ~code = rescriptCode )
339- (example , (rescriptCode , jsCode ))
340- })
341- -> Promise .all
342- })
343- -> Promise .all )
344- -> Array .flat
330+ let chuncks = modules -> chunkArray (batchSize )
331+
332+ let context = ref (0 )
333+
334+ let asyncIterator = AsyncIterator .make (async () => {
335+ let currentValue = context .contents
336+ // Increment current value
337+ context := currentValue + 1
338+
339+ {
340+ AsyncIterator .value : Some (currentValue ),
341+ done : currentValue == Array .length (chuncks ) - 1 ,
342+ }
343+ })
344+
345+ let result = []
346+ // await asyncIterator->AsyncIterator.forEach(async value =>
347+ // switch value {
348+ // | Some(value) =>
349+ // let c = Array.getUnsafe(chuncks, value)
350+ //
351+ // let a = await c->Array.map(async example => {
352+ // let id = example.id->String.replaceAll(".", "__")
353+ // let rescriptCode = example->getCodeBlocks
354+ // let jsCode = await compileTest(~id, ~code=rescriptCode)
355+ // (example, (rescriptCode, jsCode))
356+ // })->Promise.all
357+ //
358+ // Array.push(result, a)->ignore
359+ //
360+ // | None => ()
361+ // }
362+ // )
363+ let processMyAsyncIterator = async () => {
364+ // ReScript doesn't have `for ... of` loops, but it's easy to mimic using a while loop.
365+ let break = ref (false )
366+
367+ while ! break .contents {
368+ // Await the next iterator value
369+ let {value , done } = await asyncIterator -> AsyncIterator .next
370+
371+ // Exit the while loop if the iterator says it's done
372+ break := done
373+
374+ // This will log the (int) value of the current async iteration, if a value was returned.
375+ switch value {
376+ | Some (index ) =>
377+ let c = Array .getUnsafe (chuncks , index )
378+
379+ let a =
380+ await c
381+ -> Array .map (async example => {
382+ let id = example .id -> String .replaceAll ("." , "__" )
383+ let rescriptCode = example -> getCodeBlocks
384+ let jsCode = await compileTest (~id , ~code = rescriptCode )
385+ (example , (rescriptCode , jsCode ))
386+ })
387+ -> Promise .all
388+
389+ Array .push (result , a )
390+
391+ | None => ()
392+ }
393+ }
394+ }
395+
396+ processMyAsyncIterator ()-> ignore
345397
346- // let _ = c > 1
398+ let compilationResults = result -> Array .flat
399+
400+ // let compilationResults =
401+ // (await chuncks
402+ // ->Array.map(async arrExample => {
403+ // await arrExample
404+ // ->Array.map(async example => {
405+ // let id = example.id->String.replaceAll(".", "__")
406+ // let rescriptCode = example->getCodeBlocks
407+ // let jsCode = await compileTest(~id, ~code=rescriptCode)
408+ // (example, (rescriptCode, jsCode))
409+ // })
410+ // ->Promise.all
411+ // })
412+ // ->Promise.all)
413+ // ->Array.flat
347414
348415 // let compilationResults =
349416 // await modules
0 commit comments