You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The DataLoader class already functionally handles the case where you resolve with an array of promises rather than an array of values. This is nice because it allows individual items in the batch to resolve separately and prevents the case where one long-running item in the batch holds up the rest of the items which were resolved quickly.
The problem is that the type definition for the batchLoadFn does not allow for individual items in the resolved array to be promises containing V. They must either be V or Error.
Here's an example.
constdataloader=newDataLoader<TheKey,TheValue>(// This will cause a flow error because TheValue does not equal Promise<TheValue>.async(keys: $ReadOnlyArray<TheKey>): Promise<Array<Promise<TheValue>>>=>{returnkeys.map(key=>doSomethingTimeConsuming(key).then(doMoreTimeConsumingThings)// Ensure errors are cached..catch(e=>e));});
Describe the solution you'd like
The type BatchLoadFn could be updated to return Promise<$ReadOnlyArray<V | Promise<V> | Error>>.
Describe alternatives you've considered
I could just specify Promise<TheValue> as the return value for the dataloader, but then I have to do silly things like this to keep flow happy:
consttheValue=awaitawaitdataloader.load(theKey);
Additional context
I'm working on a pull request now to address this if the maintainers decide this is a good change.
The text was updated successfully, but these errors were encountered:
What problem are you trying to solve?
The DataLoader class already functionally handles the case where you resolve with an array of promises rather than an array of values. This is nice because it allows individual items in the batch to resolve separately and prevents the case where one long-running item in the batch holds up the rest of the items which were resolved quickly.
The problem is that the type definition for the batchLoadFn does not allow for individual items in the resolved array to be promises containing
V
. They must either beV
orError
.Here's an example.
Describe the solution you'd like
The type
BatchLoadFn
could be updated to returnPromise<$ReadOnlyArray<V | Promise<V> | Error>>
.Describe alternatives you've considered
I could just specify
Promise<TheValue>
as the return value for the dataloader, but then I have to do silly things like this to keep flow happy:Additional context
I'm working on a pull request now to address this if the maintainers decide this is a good change.
The text was updated successfully, but these errors were encountered: