I'm using an API that returns only a limited number of results, say 100.
I'd like to repeat a query until the return result set is < 100
which would mean I've got the last result.
So it would go like this:
You can use the expand operator for a simple "conditional repeat" behavior.
Just for the example, instead of a result set I changed the query to return a number. The following keep querying until the retrieved number is less than 100
const { defer, empty } = rxjs;
const { expand, toArray} = rxjs.operators;
const query$ = defer(async () => Math.floor(Math.random()*1000));
query$
.pipe(
expand(result => result < 100 ? empty() : query$),
toArray()
)
.subscribe(console.log);
<script src="https://unpkg.com/rxjs/bundles/rxjs.umd.min.js"></script>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments