Side effect that depends upon asynchronous value #41
-
I have this code: Future<ResourceCapsuleSideEffectController<bool>> bashrcPatchedRootUserResource(
CapsuleHandle use,
) async {
final getConnection = use(commons.connectionCapsule);
return use.asResource<bool>(
initialValue:
await (await use(rootBashrcTaggedFileUtility)).isPatched(),
getConnection: getConnection,
);
} I suppose we can not do Will be the following a good solution? Future<ResourceCapsuleSideEffectController<bool>> bashrcPatchedRootUserResource(
CapsuleHandle use,
) async {
final useAsResource = use.asResource;
final getConnection = use(commons.connectionCapsule);
return useAsResource<bool>(
initialValue: await (await use(rootBashrcTaggedFileUtility)).isPatched(),
getConnection: getConnection,
);
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Correct, you cannot have an
I might suggest hoisting the |
Beta Was this translation helpful? Give feedback.
Correct, you cannot have an
await
anywhere in the call-args of a side effect because that means the side effect will execute once the arguments finally resolve (which will then be across an async gap).I might suggest hoisting the
use(rootBashrcTaggedFileUtility)
above all of the awaits for readability purposes (up neargetConnection
), but yes, that is likely exactly how I would implement that workaround.