Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update example code for ::spawn with WaitGroup #15191

Merged
merged 2 commits into from
Nov 15, 2024

Conversation

BigBoyBarney
Copy link
Contributor

@BigBoyBarney BigBoyBarney commented Nov 13, 2024

Currently, the example in the docs for ::spawn still uses the old way of handling fibers that return nil, namely:

# Write "1" every 1 second and "2" every 2 seconds for 6 seconds.

ch = Channel(Nil).new

spawn do
  6.times do
    sleep 1.second
    puts 1
  end
  ch.send(nil)
end

spawn do
  3.times do
    sleep 2.seconds
    puts 2
  end
  ch.send(nil)
end

2.times { ch.receive }

This PR aims to modernise the example using WaitGroup.

Co-authored-by: Sijawusz Pur Rahnama <[email protected]>
@straight-shoota straight-shoota added this to the 1.15.0 milestone Nov 14, 2024
@straight-shoota straight-shoota changed the title Updated example for ::spawn Update example code for ::spawn Nov 15, 2024
@straight-shoota straight-shoota changed the title Update example code for ::spawn Update example code for ::spawn with WaitGroup Nov 15, 2024
@straight-shoota straight-shoota merged commit 32be3b6 into crystal-lang:master Nov 15, 2024
69 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants