Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Crystal WaitGroups without channels or counters

License

NotificationsYou must be signed in to change notification settings

GrottoPress/pond

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pond is aCrystal implementation of aWaitGroup, without channels or explicit counters.Pond automatically keeps track of all its fibers, and waits until all of them complete execution.

Installation

  1. Add the dependency to yourshard.yml:

    dependencies:pond:github:GrottoPress/pond
  2. Runshards install

Usage

  • Spawn fibers and wait on them:

    require"pond"pond=Pond.new1000.timesdo |_|  pond.fill { do_work }# <= Spawns fiber and passes block to itendpond.drain# <= Waits for fibers to complete

    The code above is the same as:

    require"pond"Pond.draindo |pond|1000.timesdo |_|    pond.fill { do_work }endend# <= Drains pond automatically at the end of the block
  • You may spawnnested fibers:

    In this case, allancestor fibers have to be added to the pond, otherwisePond can't guarantee any of them would complete.

    require"pond"pond=Pond.newpond.filldo  pond.filldo    pond.fill { do_work }endendpond.drain

    Note that, while you can fill a pond that was created in a another fiber, draining has to be done in the same fiber the pond was created in. This is to prevent potential deadlocks.

    require"pond"pond=Pond.newpond.fill { do_work }spawn { pond.drain }# <= Error!

Development

Run tests withcrystal spec -Dpreview_mt. You may setCRYSTAL_WORKERS environment variable withexport CRYSTAL_WORKERS=<number>, before running tests.

Contributing

  1. Fork it
  2. Switch to themaster branch:git checkout master
  3. Create your feature branch:git checkout -b my-new-feature
  4. Make your changes, updating changelog and documentation as appropriate.
  5. Commit your changes:git commit
  6. Push to the branch:git push origin my-new-feature
  7. Submit a newPull Request against theGrottoPress:master branch.

About

Crystal WaitGroups without channels or counters

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp