# How to trigger non-blocking long calculations in Makie?

**URL:** https://discourse.julialang.org/t/how-to-trigger-non-blocking-long-calculations-in-makie/90496
**Category:** Visualization
**Tags:** makie, glmakie
**Created:** [November 19, 2022, 1:30pm UTC](https://discourse.julialang.org/t/how-to-trigger-non-blocking-long-calculations-in-makie/90496 "2022-11-19T13:30:00Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Krastanov](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/krastanov/32/6817_2.png) [@Krastanov](https://discourse.julialang.org/u/Krastanov)
#### Post date: [November 19, 2022, 1:30pm UTC](https://discourse.julialang.org/t/how-to-trigger-non-blocking-long-calculations-in-makie/90496/1 "2022-11-19T13:30:00Z")

</div>

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.

```julia
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
end
F

```

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.

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [November 19, 2022, 1:35pm UTC](https://discourse.julialang.org/t/how-to-trigger-non-blocking-long-calculations-in-makie/90496/2 "2022-11-19T13:35:19Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Krastanov](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/krastanov/32/6817_2.png) [@Krastanov](https://discourse.julialang.org/u/Krastanov)
#### Post date: [November 19, 2022, 1:48pm UTC](https://discourse.julialang.org/t/how-to-trigger-non-blocking-long-calculations-in-makie/90496/3 "2022-11-19T13:48:16Z")

</div>

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

```julia
on(b.clicks) do _
    @async begin
        running[] = true
        sleep(1)
        running[] = false
    end
end

```
