# @async while loop not looping

**URL:** https://discourse.julialang.org/t/async-while-loop-not-looping/83156
**Category:** General Usage
**Tags:** question
**Created:** [June 22, 2022, 12:41am UTC](https://discourse.julialang.org/t/async-while-loop-not-looping/83156 "2022-06-22T00:41:05Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![wiseac](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wiseac/32/36768_2.png) [@wiseac](https://discourse.julialang.org/u/wiseac)
#### Post date: [June 22, 2022, 12:41am UTC](https://discourse.julialang.org/t/async-while-loop-not-looping/83156/1 "2022-06-22T00:41:06Z")

</div>

Im trying to loop two tasks but it will only run through it once and not loop. This is what my code looks like. I have the second task commented out because im trying to just get the first one working.

If i remove the @async then it throws an error of the task not being runnable.

```julia
TPH = @task (GetTPH());
Mak = @task (MakieWindow());

function ttt()
    @async while true
    schedule(TPH);
    wait(TPH);
    #schedule(Mak);
    #wait(Mak);
    sleep(5)
    end
end

```

I am new to tasks and trying to get a Gtk and Makie to update and run variables simultaneously.

Thanks,  
W

---

<div class="post-metadata">

### Author: ![skleinbo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skleinbo/32/36080_2.png) [@skleinbo](https://discourse.julialang.org/u/skleinbo)
#### Post date: [June 22, 2022, 7:14am UTC](https://discourse.julialang.org/t/async-while-loop-not-looping/83156/2 "2022-06-22T07:14:09Z")

</div>

After the first loop iteration, the task `TPH` is done and cannot be scheduled again.

But it looks like you want `GetTPH` and `MakieWindow` to run sequentially anyway, so why not simply do

```julia
function ttt()
    @async while true
        GetTPH()
        MakieWindow()
        sleep(5)
    end
end
```

---

<div class="post-metadata">

### Author: ![wiseac](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wiseac/32/36768_2.png) [@wiseac](https://discourse.julialang.org/u/wiseac)
#### Post date: [June 22, 2022, 2:17pm UTC](https://discourse.julialang.org/t/async-while-loop-not-looping/83156/3 "2022-06-22T14:17:33Z")

</div>

Ya know sometimes you just overthink everything… That worked!

I believe i was overthinking it because Gtk uses some funny button/function callbacks that i initally setup but then never considered changing. (I was also looking for a change to understand tasks better).

just out of curiosity why cant the task be scheduled again?
