Repository navigation
It would be better if allSettled will return results of effect execution #385
Description
Activity
- addedquestionFurther information is requestedFurther information is requested
on Sep 21, 2020 This imply that allSettled might fail (because if you get results, you should get errors too), if this is an expected behavior, then we could implement that idea
Oh, looks like errors support is a breaking change, as there are projects, which expect that allSettled is never throw an error
But we can return value with type{status: 'done', value: Done} | {status: 'fail', value: Fail}Reacted by Ilia Lebedev- addedenhancementNew feature or requestNew feature or requestcoreeffector packageeffector package
on Sep 21, 2020 I've thought again, and seems allSettled semantic really shouldn't return results/throw errors.
And maybe we need another method/helper for calling effects for specific scope directly.Maybe like:
const user = await getUserFx.withScope(scope)({ userId: 31 }); // or const user = await scope.exec(getUserFx, { userId: 31 });
But in this case we're losing ability "Call provided event in scope and wait for finishing all the triggered effect." from
allSettledalthough on backend we should wait for all asyncs.But we can return value with type {status: 'done', value: Done} | {status: 'fail', value: Fail}
Actually I think your variant is very good. Semantic is really good, no errors, but details.
Okay, then we'll implement that in next minor release
Reacted by Ilia LebedevReacted by Ilia LebedevUpdates: this feature was implemented in runtime and in typings, the last question is what this method should return when used with events? Is it ok to return
void? Or if we decided to return similar object, whichstatusshould be used? Can we add return object later?After thinking about this for some time, I came to conclusion that calling
allSettledwith event should not return status object, at least it not useful in discussed case, but it is ok to introduce it laterReacted by Sova and Ilia LebedevImplemented in 21.4.0
@zerobias Thank you very much! 👍
I'm trying to write SSR Isomorphic application (with Next.js) and I start using Fork api (scopes).
As I could understand (maybe wrong) I should use
allSettledfunc when I use effects on backend-side.But If I wrap effects into
allSettledI'm loosing my ability to read results of effect execution (returning values). And it very uncomfortable.I expected this flavour of using:
but
userwill beundefinedin this case...For contrast calling
const user = await getUserFx({ userId: 31 };will return user data.Maybe in Effector exists another methods for call effects on the backend with specifying certain scope where I could get results of execution. I couldn't find.