# Help understanding example dealing with @async/wait/yield/schedule in Redefining Methods section

**URL:** <https://discourse.julialang.org/t/help-understanding-example-dealing-with-async-wait-yield-schedule-in-redefining-methods-section/6980>\
**Category:** General Usage\
**Tags:** question\
**Created:** [November 9, 2017, 12:22pm UTC](https://discourse.julialang.org/t/help-understanding-example-dealing-with-async-wait-yield-schedule-in-redefining-methods-section/6980 "2017-11-09T12:22:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![angelv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/angelv/32/133_2.png) [@angelv](https://discourse.julialang.org/u/angelv)\
**Post date:** [November 9, 2017, 12:22pm UTC](https://discourse.julialang.org/t/help-understanding-example-dealing-with-async-wait-yield-schedule-in-redefining-methods-section/6980/1 "2017-11-09T12:22:08Z")

</div>

Hi,

I’m reading the Redefining Methods section ([https://docs.julialang.org/en/stable/manual/methods/#Redefining-Methods-1](https://docs.julialang.org/en/stable/manual/methods/#Redefining-Methods-1)), and I don’t understand it properly.

The lines that give me some trouble are:

```julia
julia> f(x::Int) = "definition for Int"
julia> t = @async f(wait()); yield();
julia> wait(schedule(t, 1))

```

And here the questions:

1. Do we need yield() in the definition of t? As I understand it yield() will just return to the scheduler, but since this is the las instruction for t, just removing this line will end the execution of t and also return to the scheduler, right?

2. wait() will block the current task until woken up by schedule. Just to make sure, the task is actually the @async block, right? I mean, it is not stopping inside f, but just before the actual call to f is made?

3. In wait(schedule(t,1)), why do we need the wait? Trying the code in the REPL I see that if we only issue schedule(t,1), the task is finished, but I don’t get the “definition for Int” string. So, for tasks, if we want to keep the returned value, we always need to use wait?

4. And the last one. The 1 in schedule(t,1) is passed to the function f, but I don’t understand the syntax properly. The documentation for schedule says: _If a second argument val is provided, it will be passed to the task (via the return value of yieldto) when it runs again._ So, I guess this is basically the same as the previous point: schedule passes number 1 to the task t, which was wait-ing, so this is the return value of wait(), which is passed to the function f.

Such a small code, so many questions 🙂  
Thanks,  
AdV

---

<div class="post-metadata">

**Author:** ![jameson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jameson/32/23_2.png) [@jameson](https://discourse.julialang.org/u/jameson)\
**Post date:** [November 18, 2017, 5:44pm UTC](https://discourse.julialang.org/t/help-understanding-example-dealing-with-async-wait-yield-schedule-in-redefining-methods-section/6980/2 "2017-11-18T17:44:45Z")

</div>

> [@angelv](#):
>
> Do we need yield() in the definition of t?

It’s after the definition, not in it, so this starts t running.
