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
I made a function that first asks my API for an AWS S3 signed URL, and then uploads a file to that signed URL (using Task.andThen). Now I wanted to show the upload progress, but learned that Http.task does not take a tracker. It felt nice having a function that let me upload a file without having to think about the presigned URL, but now I have to break it up into two steps and use Http.request instead.
Reacted by Guy Brand, toastal, Rónán, Dimitri B., Jared Ramirez, Steven Yappie and Isaac Gregson
I wanted a waitAtLeast function for my form submissions because sometimes that request would react before the user knew, additionally sometimes I raise a toast on the screen and don't want it to popup and disappear too quickly if the request is fast. If Cmd/Tasks were like Futures, I'd run a timer and the request in parallel and await both the results (ditching the timer) Parallelism isn't really supported in that sort of way. To get around that, I've used Task.andThen like:
waitAtLeast:Int->Taskxa->TaskxawaitAtLeast delay task =-- Sure would be nice to have do notation here-- do-- start <- Time.now-- value <- task-- end <- Time.now-- let toWait = end - start - delay-- . . .-- desugared into:Time.now
|>Task.andThen
(\start ->
task
|>Task.andThen
(\value ->Time.now
|>Task.andThen
(\end ->let
toWait :Int
toWait =
delay
-Time.posixToMillis end
+Time.posixToMillis start
inif toWait <=0thenTask.succeed value
elseProcess.sleep (toFloat toWait)|>Task.andThen (\_ ->Task.succeed value))))
Turning a Http.Request into a Task, I get the waitAtLeast part I wanted, but now that it's a Task I have no access to the tracker.
Activity
jaredramirez commentedon Sep 23, 2019
Maybe relevant: https://discourse.elm-lang.org/t/upload-files-to-s3/4314/14?u=jaredramirez
lydell commentedon Nov 1, 2019
Here’s a use case.
I made a function that first asks my API for an AWS S3 signed URL, and then uploads a file to that signed URL (using
Task.andThen). Now I wanted to show the upload progress, but learned thatHttp.taskdoes not take atracker. It felt nice having a function that let me upload a file without having to think about the presigned URL, but now I have to break it up into two steps and useHttp.requestinstead.toastal commentedon Jan 6, 2020
Use case 2:
I wanted a
waitAtLeastfunction for my form submissions because sometimes that request would react before the user knew, additionally sometimes I raise a toast on the screen and don't want it to popup and disappear too quickly if the request is fast. If Cmd/Tasks were like Futures, I'd run a timer and the request in parallel and await both the results (ditching the timer) Parallelism isn't really supported in that sort of way. To get around that, I've usedTask.andThenlike:Turning a
Http.Requestinto aTask, I get thewaitAtLeastpart I wanted, but now that it's aTaskI have no access to thetracker.jjant commentedon Sep 29, 2021
@evancz ?