Skip to content

Commit

Permalink
Updated example for ::spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
BigBoyBarney committed Nov 13, 2024
1 parent caf57c2 commit aa49f2b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/concurrent.cr
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,34 @@ end

# Spawns a new fiber.
#
# The newly created fiber doesn't run as soon as spawned.
# NOTE: The newly created fiber doesn't run as soon as spawned.
#
# Example:
# ```
# # Write "1" every 1 second and "2" every 2 seconds for 6 seconds.
#
# ch = Channel(Nil).new
# require "wait_group"
# wg = WaitGroup.new 2
#
# spawn do
# 6.times do
# sleep 1.second
# puts 1
# end
# ch.send(nil)
# ensure
# wg.done
# end
#
# spawn do
# 3.times do
# sleep 2.seconds
# puts 2
# end
# ch.send(nil)
# ensure
# wg.done
# end
#
# 2.times { ch.receive }
# wg.wait
# ```
def spawn(*, name : String? = nil, same_thread = false, &block)
fiber = Fiber.new(name, &block)
Expand Down

0 comments on commit aa49f2b

Please sign in to comment.