I’ve created a small package PriorityChannels.jl that implements a
PriorityChannel that mimics
Base.Channel , but where each element is associated with a priority.
take! always returns the highest priority element. Internally, a heap is used to keep track of priorities. Usage example in the readme.
put!(pc, element, priority::Real)lower number indicates a higher priority (default = 0).
PriorityChannelcan not be unbuffered (of length 0) and must have a positive length.
take!(pc)returns the highest priority item,
PriorityChannelthus acts like a priority queue instead of a FIFO queue like
- Pretty much all other functionality should be the same, including all constructors.
using Pkg pkg"add PriorityChannels"
Happy New Year, may it be full of wisely prioritized and rewarding tasks!