This repository has been archived by the owner. It is now read-only.
wait_group
wait_group
WaitGroup waits for collection of spawn to finish.
Installation
Add this to your application's shard.yml
:
dependencies:
wait_group:
github: takaishi/wait_group
Usage
require "wait_group"
def worker(msg : String)
wg = WaitGroup.new
receiver = Channel(String).new
fin = Channel(Bool).new
spawn do
3.times do |i|
wg.add(1)
spawn do
receiver.send("#{i} #{msg} done")
wg.done
end
end
wg.wait
fin.send(true)
end
return receiver, fin
end
receiver, fin = worker("job")
loop do
index, value = Channel.select(receiver.receive_op, fin.receive_op)
case index
when 0
puts(value)
when 1
break
end
end
Development
TODO: Write development instructions here
Contributing
- Fork it ( https://github.com/takaishi/wait_group/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
Contributors
- takaishi Ryo Takaishi - creator, maintainer
Repository
wait_group
Owner
Statistic
- 0
- 0
- 0
- 0
- 0
- about 9 years ago
- March 27, 2016
License
MIT License
Links
Synced at
Sun, 27 Apr 2025 11:39:25 GMT
Languages