Skip to content

Commit 180695d

Browse files
authored
Merge pull request #1 from Satvik/remove-at-async-from-docs
Replace @async mentions with Threads.@Spawn in .md files
2 parents 20b3af3 + dc188b9 commit 180695d

File tree

9 files changed

+29
-29
lines changed

9 files changed

+29
-29
lines changed

doc/src/base/parallel.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
```@docs
44
Core.Task
55
Base.@task
6-
Base.@async
6+
Base.Threads.@spawn
77
Base.asyncmap
88
Base.asyncmap!
99
Base.current_task
@@ -138,7 +138,7 @@ end
138138
139139
ev = OneWayEvent()
140140
@sync begin
141-
@async begin
141+
Threads.@spawn begin
142142
wait(ev)
143143
println("done")
144144
end

doc/src/devdocs/probes.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ Now we can start `bpftrace` and have it monitor `rt__new__task` for *only* this
206206

207207
And if we spawn a single task:
208208

209-
`@async 1+1`
209+
`Threads.@spawn 1+1`
210210

211211
we see this task being created:
212212

@@ -215,8 +215,8 @@ we see this task being created:
215215
However, if we spawn a bunch of tasks from that newly-spawned task:
216216

217217
```julia
218-
@async for i in 1:10
219-
@async 1+1
218+
Threads.@spawn for i in 1:10
219+
Threads.@spawn 1+1
220220
end
221221
```
222222

doc/src/manual/asynchronous-programming.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ the next input prompt appears. That is because the REPL is waiting for `t`
6464
to finish before proceeding.
6565

6666
It is common to want to create a task and schedule it right away, so the
67-
macro [`@async`](@ref) is provided for that purpose --- `@async x` is
68-
equivalent to `schedule(@task x)`.
67+
macro [`Threads.@spawn`](@ref) is provided for that purpose --- `Threads.@spawn x` is
68+
equivalent to `task = @task x; task.sticky = false; schedule(task)`.
6969

7070
## Communicating with Channels
7171

@@ -186,7 +186,7 @@ A channel can be visualized as a pipe, i.e., it has a write end and a read end :
186186

187187
# we can schedule `n` instances of `foo` to be active concurrently.
188188
for _ in 1:n
189-
errormonitor(@async foo())
189+
errormonitor(Threads.@spawn foo())
190190
end
191191
```
192192
* Channels are created via the `Channel{T}(sz)` constructor. The channel will only hold objects
@@ -264,10 +264,10 @@ julia> function make_jobs(n)
264264
265265
julia> n = 12;
266266
267-
julia> errormonitor(@async make_jobs(n)); # feed the jobs channel with "n" jobs
267+
julia> errormonitor(Threads.@spawn make_jobs(n)); # feed the jobs channel with "n" jobs
268268
269269
julia> for i in 1:4 # start 4 tasks to process requests in parallel
270-
errormonitor(@async do_work())
270+
errormonitor(Threads.@spawn do_work())
271271
end
272272
273273
julia> @elapsed while n > 0 # print out results

doc/src/manual/distributed-computing.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ An important thing to remember is that, once fetched, a [`Future`](@ref Distribu
123123
locally. Further [`fetch`](@ref) calls do not entail a network hop. Once all referencing [`Future`](@ref Distributed.Future)s
124124
have fetched, the remote stored value is deleted.
125125

126-
[`@async`](@ref) is similar to [`@spawnat`](@ref), but only runs tasks on the local process. We
126+
[`Threads.@spawn`](@ref) is similar to [`@spawnat`](@ref), but only runs tasks on the local process. We
127127
use it to create a "feeder" task for each process. Each task picks the next index that needs to
128128
be computed, then waits for its process to finish, then repeats until we run out of indices. Note
129129
that the feeder tasks do not begin to execute until the main task reaches the end of the [`@sync`](@ref)
@@ -657,7 +657,7 @@ julia> function make_jobs(n)
657657
658658
julia> n = 12;
659659
660-
julia> errormonitor(@async make_jobs(n)); # feed the jobs channel with "n" jobs
660+
julia> errormonitor(Threads.@spawn make_jobs(n)); # feed the jobs channel with "n" jobs
661661
662662
julia> for p in workers() # start tasks on the workers to process requests in parallel
663663
remote_do(do_work, p, jobs, results)
@@ -896,7 +896,7 @@ conflicts. For example:
896896
```julia
897897
@sync begin
898898
for p in procs(S)
899-
@async begin
899+
Threads.@spawn begin
900900
remotecall_wait(fill!, p, S, p)
901901
end
902902
end
@@ -978,7 +978,7 @@ and one that delegates in chunks:
978978
julia> function advection_shared!(q, u)
979979
@sync begin
980980
for p in procs(q)
981-
@async remotecall_wait(advection_shared_chunk!, p, q, u)
981+
Threads.@spawn remotecall_wait(advection_shared_chunk!, p, q, u)
982982
end
983983
end
984984
q

doc/src/manual/faq.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ Consider the printed output from the following:
943943

944944
```jldoctest
945945
julia> @sync for i in 1:3
946-
@async write(stdout, string(i), " Foo ", " Bar ")
946+
Threads.@spawn write(stdout, string(i), " Foo ", " Bar ")
947947
end
948948
123 Foo Foo Foo Bar Bar Bar
949949
```
@@ -956,7 +956,7 @@ in the above example results in:
956956

957957
```jldoctest
958958
julia> @sync for i in 1:3
959-
@async println(stdout, string(i), " Foo ", " Bar ")
959+
Threads.@spawn println(stdout, string(i), " Foo ", " Bar ")
960960
end
961961
1 Foo Bar
962962
2 Foo Bar
@@ -969,7 +969,7 @@ You can lock your writes with a `ReentrantLock` like this:
969969
julia> l = ReentrantLock();
970970
971971
julia> @sync for i in 1:3
972-
@async begin
972+
Threads.@spawn begin
973973
lock(l)
974974
try
975975
write(stdout, string(i), " Foo ", " Bar ")

doc/src/manual/methods.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ Start some other operations that use `f(x)`:
614614
julia> g(x) = f(x)
615615
g (generic function with 1 method)
616616
617-
julia> t = @async f(wait()); yield();
617+
julia> t = Threads.@spawn f(wait()); yield();
618618
```
619619

620620
Now we add some new methods to `f(x)`:
@@ -639,7 +639,7 @@ julia> g(1)
639639
julia> fetch(schedule(t, 1))
640640
"original definition"
641641
642-
julia> t = @async f(wait()); yield();
642+
julia> t = Threads.@spawn f(wait()); yield();
643643
644644
julia> fetch(schedule(t, 1))
645645
"definition for Int"

doc/src/manual/networking-and-streams.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ Let's first create a simple server:
233233
```julia-repl
234234
julia> using Sockets
235235
236-
julia> errormonitor(@async begin
236+
julia> errormonitor(Threads.@spawn begin
237237
server = listen(2000)
238238
while true
239239
sock = accept(server)
@@ -305,11 +305,11 @@ printed the message and waited for the next client. Reading and writing works in
305305
To see this, consider the following simple echo server:
306306

307307
```julia-repl
308-
julia> errormonitor(@async begin
308+
julia> errormonitor(Threads.@spawn begin
309309
server = listen(2001)
310310
while true
311311
sock = accept(server)
312-
@async while isopen(sock)
312+
Threads.@spawn while isopen(sock)
313313
write(sock, readline(sock, keep=true))
314314
end
315315
end
@@ -319,7 +319,7 @@ Task (runnable) @0x00007fd31dc12e60
319319
julia> clientside = connect(2001)
320320
TCPSocket(RawFD(28) open, 0 bytes waiting)
321321
322-
julia> errormonitor(@async while isopen(clientside)
322+
julia> errormonitor(Threads.@spawn while isopen(clientside)
323323
write(stdout, readline(clientside, keep=true))
324324
end)
325325
Task (runnable) @0x00007fd31dc11870
@@ -357,10 +357,10 @@ ip"74.125.226.225"
357357

358358
All I/O operations exposed by [`Base.read`](@ref) and [`Base.write`](@ref) can be performed
359359
asynchronously through the use of [coroutines](@ref man-tasks). You can create a new coroutine to
360-
read from or write to a stream using the [`@async`](@ref) macro:
360+
read from or write to a stream using the [`Threads.@spawn`](@ref) macro:
361361

362362
```julia-repl
363-
julia> task = @async open("foo.txt", "w") do io
363+
julia> task = Threads.@spawn open("foo.txt", "w") do io
364364
write(io, "Hello, World!")
365365
end;
366366
@@ -379,7 +379,7 @@ your program to block until all of the coroutines it wraps around have exited:
379379
julia> using Sockets
380380
381381
julia> @sync for hostname in ("google.com", "github.com", "julialang.org")
382-
@async begin
382+
Threads.@spawn begin
383383
conn = connect(hostname, 80)
384384
write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n")
385385
readline(conn, keep=true)

doc/src/manual/performance-tips.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1723,7 +1723,7 @@ using Distributed
17231723
responses = Vector{Any}(undef, nworkers())
17241724
@sync begin
17251725
for (idx, pid) in enumerate(workers())
1726-
@async responses[idx] = remotecall_fetch(foo, pid, args...)
1726+
Threads.@spawn responses[idx] = remotecall_fetch(foo, pid, args...)
17271727
end
17281728
end
17291729
```

doc/src/manual/running-external-programs.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,8 @@ will attempt to store the data in the kernel's buffers while waiting for a reade
332332
Another common solution is to separate the reader and writer of the pipeline into separate [`Task`](@ref)s:
333333

334334
```julia
335-
writer = @async write(process, "data")
336-
reader = @async do_compute(read(process, String))
335+
writer = Threads.@spawn write(process, "data")
336+
reader = Threads.@spawn do_compute(read(process, String))
337337
wait(writer)
338338
fetch(reader)
339339
```

0 commit comments

Comments
 (0)