# Compiling with @async

**URL:** <https://discourse.julialang.org/t/compiling-with-async/129726>\
**Category:** New to Julia\
**Tags:** async\
**Created:** [June 7, 2025, 5:32pm UTC](https://discourse.julialang.org/t/compiling-with-async/129726 "2025-06-07T17:32:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Doug719](https://avatars.discourse-cdn.com/v4/letter/d/0ea827/32.png) [@Doug719](https://discourse.julialang.org/u/Doug719)\
**Post date:** [June 7, 2025, 5:32pm UTC](https://discourse.julialang.org/t/compiling-with-async/129726/1 "2025-06-07T17:32:43Z")

</div>

If I enter  
`t1 = @async begin; sleep(5); println("done1"); end`  
at the julia REPL, I get

```julia
  Task (runnable, started) @0x00007f575a6c3d00

    julia> done1

```

If I compile and run

```julia
function main()
  t1 = @async begin; sleep(5); println("done1"); end 
end

main()

```

I get no error messages and output  
`startup from ~/.julia/config.startup.jl`

Why can’t I get the same output as the REPL?

---

<div class="post-metadata">

**Author:** ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)\
**Post date:** [June 7, 2025, 6:25pm UTC](https://discourse.julialang.org/t/compiling-with-async/129726/2 "2025-06-07T18:25:36Z")

</div>

Because your program exits before the async task finishes. You need to `wait` for it to finish.
