@sync usage and better documentation for Asynchronous Programming

I am trying to understand the usage of @sync and @async macros in Julia. I am trying to get this MWE to work and the program does not terminate. Any help is appreciated.

function process_node(nodes, id)
    @show id
    sleep(1.0)
    nodes[id] = true 
    return
end 

function main() 
    nodes = Dict( i => false for i in 1:10 )
    jobs = Channel{Int}(15)
    for i in 1:10 
        put!(jobs, i)
    end 
    @sync for id in jobs
        @async process_node(nodes, id)
    end 
    println("done")
end 


main()

The program never gets to the line println("done"). I do not know why.

Also, if you can point me to some reference or blog that has a tutorial for using co-routines without talking about any distributed programming, it would be great.

Thanks in advance.

for i in 1:10
    put!(jobs, i)
end
close(jobs)

The for id in jobs loop doesn’t exit until the channel is empty and closed. So you need to close the channel for the loop to complete. Since closing the channel before you start the loop may seem weird, you could do something like:

jobs = Channel{Int}(5)

@async begin
    for i in 1:10
        put!(jobs, i)
    end
    close(jobs)
end