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 @mybigman the reason it works like this is because it's analogous to Promise.all which works with arrays and outputs arrays.
on the other hand I think it might be possible to create a different higher order function that would accept by name and also output by name
ai is giving me this adjustment:
exportfunctionuseParallelTask<RecordTypeextendsRecord<string,any>>(...tasks: Task<any,any>[]): Task<RecordType,any>{returnuseTask(function*(signal, ...args){// Perform each task and attach cancellation signalconstinstances=tasks.map((task)=>{constinstance=task.perform(...args).canceledOn(signal);return{name: task.name, instance };});// Wait for all tasks to completeconstresults=yieldPromise.all(instances.map(item=>item.instance));// Map results back to object with task names as keysconstnamedResults={}asRecordType;instances.forEach((item,index)=>{(namedResultsasany)[item.name]=results[index];});returnnamedResults;});}
Perhaps this version might work for you? (hope it actually works 🙏️ I haven't given ran it )
Hopefully this project isnt dead as its quite nice.
With
useParallelTask
using your example.It appears I cant access the tasks by names which seems problematic as it means I have to check the order providing they go in and come out the same.
Would be nice if you can access them by name?
The text was updated successfully, but these errors were encountered: