https://github.com/jgaskins/mpsc
Multi-Producer/Single-Consumer channels in Crystal
https://github.com/jgaskins/mpsc
channels crystal
Last synced: 11 months ago
JSON representation
Multi-Producer/Single-Consumer channels in Crystal
- Host: GitHub
- URL: https://github.com/jgaskins/mpsc
- Owner: jgaskins
- License: mit
- Created: 2021-02-28T21:29:37.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-11-28T00:01:11.000Z (over 4 years ago)
- Last Synced: 2025-05-06T18:16:17.669Z (11 months ago)
- Topics: channels, crystal
- Language: Crystal
- Homepage:
- Size: 5.86 KB
- Stars: 11
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mpsc
MPSC is an implementation of a multi-producer/single-consumer channel. This is useful if you only ever consume a channel from within a single fiber.
MPSC channels are unbounded. Calling `send` will never block.
**Note:** This shard is _not_ suitable for consuming the same channel from multiple fibers, even if they don't consume it concurrently. Once you call `receive` from a fiber, the receiving end of the channel is locked to that fiber.
## Installation
1. Add the dependency to your `shard.yml`:
```yaml
dependencies:
mpsc:
github: jgaskins/mpsc
```
2. Run `shards install`
## Usage
```crystal
require "mpsc"
channel = MPSC::Channel(String).new
spawn channel.send "hello"
channel.receive # "hello"
```
## Contributing
1. Fork it ()
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Reformat the code (`crystal tool format .`)
4. Commit your changes (`git commit -am 'Add some feature'`)
5. Push to the branch (`git push origin my-new-feature`)
6. Create a new Pull Request
## Contributors
- [Jamie Gaskins](https://github.com/jgaskins) - creator and maintainer