How to trigger non-blocking long calculations in Makie?

I want to do the following in Makie: press a button which triggers long computation that interactively updates the plot. I can’t seem to figure it out. Here is a MWE:

This example uses the bool observable running to track whether the long computation is triggered.

F = Figure(resolution=(600,600))
F[1,1] = inputgrid = GridLayout(tellwidth = false)
running = Observable(false)
b = Button(F, label = @lift(string($running)))
inputgrid[1,1] = b

on(b.clicks) do _
    running[] = true # this should change the button label from "false" to "true"
    sleep(1) # this is the long computation
    running[] = false # resetting the button label

When I press the button, the plot becomes non-responsive for a second and the label does not change. I am expecting the label to change immediately on button press to “true” and then change back to “false” after a second.

What am I doing wrong? Are notify calls incapable of working when called from withing an on call? How can I make the button turn to “true” on click and then on its own turn back to “false”?

This is on Julia 1.8.2 and GLMakie v0.7.3.

If sleeping happens on the main thread then no rendering can happen (rendering is done asynchronously but not on a different thread). You can use @async begin around the stuff in the on call and the whole thing will be interleaved with the rendering using coroutines, even if there’s still only one thread.


Thank you! Indeed, all I needed was to add @async

on(b.clicks) do _
    @async begin
        running[] = true
        running[] = false