Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/falood/queuex
Elixir Priority Queue
https://github.com/falood/queuex
Last synced: 2 months ago
JSON representation
Elixir Priority Queue
- Host: GitHub
- URL: https://github.com/falood/queuex
- Owner: falood
- License: wtfpl
- Created: 2015-09-03T09:09:54.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-01-10T15:33:36.000Z (almost 8 years ago)
- Last Synced: 2024-09-16T17:44:17.115Z (3 months ago)
- Language: Elixir
- Size: 15.6 KB
- Stars: 11
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - Priority Queue with multiple backends. (Queue)
- fucking-awesome-elixir - queuex - Priority Queue with multiple backends. (Queue)
- awesome-elixir - queuex - Priority Queue with multiple backends. (Queue)
README
Queuex
======> Queuex is a Priority Queue.
[![Build Status](https://img.shields.io/travis/falood/queuex.svg?style=flat-square)](https://travis-ci.org/falood/queuex)
[![Hex.pm Version](https://img.shields.io/hexpm/v/queuex.svg?style=flat-square)](https://hex.pm/packages/queuex)
[![Hex.pm Downloads](https://img.shields.io/hexpm/dt/queuex.svg?style=flat-square)](https://hex.pm/packages/queuex)These backends are supported:
1. List (Queuex.Backends.List)
2. Red-black tree (Queue.Backends.RedBlackTree)## Usage
1. Define your queue module.
```elixir
defmodule MyQueue do
use Queuex,
max_num: 3, # (required, integer) max worker numbers
worker: :my_worker, # (required, atom) callback function
backend: # (optional, Queuex.Backends.List(default) or Queuex.Backends.RedBlackTree) queue backend
default_priority: 1, # (optional, integer, default: 1) default priority for &MyQueue.push/1, smaller means high priority
unique: false # (optional, true or false(default) or :strictly) duplication term is allowned in queue. false => don't check, true => check with `backend.has_value?/2`, :strictly => check with `backend.has_priority_value?/3`def my_worker(term, _priority) do
:timer.sleep(10000)
term |> IO.inspect
end
end
```2. supervise your queue module
```elixir
[ MyQueue.child_spec
... # your other supervisor or worker
] |> supervise strategy: :one_for_one
```3. push term to queue
```elixir
MyQueue.push(term, priority)
MyQueue.push(term) # push term with default priority
```## TODO
- [ ] Benchmark
- [ ] Document