Concurrency in Elm

I have a really expensive calculator that I need to run in my "update" function.

When it starts, the entire application is blocked until it ends.

Is there a way to run this code asynchronously to prevent blocking? (not using ports and staying in elms)

+4
source share
2 answers

Elm Tasks do not support proactive multitasking.

With the help of, Process.spawnyou can create tasks that will be switched by context when used as arguments in Task.andThen.

, Task x Process.Id, , .

Process.Id.

+1

. , , :

DoHeavyStuff a b ->
    let
        task param1 param2 =
            Task.succeed 1
            `Task.andThen` (\_ -> Task.succeed <| expensive param1 param2)
    in
    (model, Task.perform NoOp FinishedWork (task a b))

FinishedWork result ->
    ...
0

Source: https://habr.com/ru/post/1651774/


All Articles