Task/Process instanciating

Hi all. How i can create Task.Task or Process.Process instance with my pure elm code(not from HTTP request or other JS interoop things). I want to create Task with some async calculations and get a Msg after completion. And maybe this is a related question: How i can get a Router.Router object for using “sendToApp” and “sendToSelf” functions?

You can start a task chain with Task.succeed, even Task.succeed ()

You can create a Process with spawn, but I’ve never figured how to use Process in a way that could communicate in either direction. The notes at the bottom of the docs indicate it’s an incomplete feature.

Router and the event manager functions are integration points for native code, which only elm/ packages can touch.

1 Like

As the documentation for Process notes, make sure you use Task.andThen everywhere you want a possible suspension of your calculation (where the Elm runtime can shift over to doing some other work). If you just take an expensive pure function and stick it all in a single Task.succeed you’ll end up with no real async-ness and just that single pure function hogging your single thread until it finishes. You’ll need to rewrite your pure function with Task.andThen points wherever it’s acceptable for the function to be interrupted by the Elm runtime to allow something else to run.

As a minor side note, if anyone who has commit rights to elm-core is reading: can we change the language of “I think we can do better than the hopelessly bad concurrency model of node.js?” The Elm community rightfully bristles whenever someone casually brushes aside all the trade-offs Elm has considered in establishing certain limitations in its programming model and talks about some perceived problem that makes Elm “hopelessly bad” or “unfit for production.” This feels like us doing the same to another programming model.


This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.