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
Hi there, I've create a lib heavily inspired by dataloader, that makes it easier to implement parallel async calls batching using simply annotations (or creating a custom Batcher if you want), you just need to decorate your class method with @InBatches() and all the magic happens in the background for you, check it out.
import{InBatches}from'inbatches';classMyService{// (optional) overloaded method, where you define the keys as `number` and the return type as `string` for typingsasyncfetch(keys: number): Promise<string>;// in reality the Decorator will wrap this method and it will never be called with a single key :) @InBatches()// This method is now batch-enabledasyncfetch(keys: number|number[]): Promise<string|string[]>{if(Array.isArray(keys)){returnthis.db.getMany(keys);}// the Decorator will wrap this method and because of that it will never be called with a single keythrownewError('It will never be called with a single key 😉');}}constservice=newMyService();constresult=[1,2,3,4,5].map(asyncid=>{returnawaitservice.fetch(id);});// The result will be an array of results in the same order as the keysresult.then(results=>{console.log(results);// Output: [{ id: 1, name: 'Result for key 1' }, ...]});
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there, I've create a lib heavily inspired by dataloader, that makes it easier to implement parallel async calls batching using simply annotations (or creating a custom Batcher if you want), you just need to decorate your class method with
@InBatches()and all the magic happens in the background for you, check it out.https://github.com/onhate/inbatches
Beta Was this translation helpful? Give feedback.
All reactions