Reviving large arrays in batches
Reviving large objects can block the main thread for too long. In the browser, for example, this might cause the page to be unresponsive for a noticeable period of time.
This recipe defines a strategy for reviving large arrays in batches, so that other work can be interleaved. Inevitably, the total time that it will take to revive the array will increase, but the page will remain responsive.
Please note that the following applies to the reviving phase done by Modélico, not the parsing of JSON strings into plain JS objects.
We will use the following object with information about a Library
that includes a large catalogue of Book
items:
The idea is to revive a version of the library with an empty catalogue and revive the catalogue in batches.
Instead of doing the following,
we first revive the library with an empty catalogue:
Then, we are going to use an asyncMap
function (see implementation below) to revive the catalogue, which is a Modelico.List
of Books
.
asyncMap(fn, arr, options)
Last updated