I have a pipe like this:
S.pipe([
getRequestFile, // not async
S.chain(saveTemporary), // not async
S.chain(copyImageToPublicPath), // async
S.chain(copyFileToPath), // async
S.chain(someLoggingFunction), // not async
S.chain(sendResponse), // not async
]);
There are 2 async functions in middle of this pipe.
I want to await
for copyImageToPublicPath
and then await
for copyFileToPath
and then continue the normal flow
After some search I found that there is Future.tryP
function for doing async
but how can I use Fluture
in middle of this pipe?
It's a matter of lining up the types.
Let's make up some type definitions to use in an example:
Now, let create our program step by step…
To operate on the
b
inside aFuture a b
value we use eitherS.map
orS.chain
.S.map
can lead to unwanted nesting:We could use
S.chain
to avoid this nesting:It may be helpful to think of
S.map
adding to some computation an operation that cannot fail, whereasS.chain
adds a computation that can fail.