Cfchannel
MPSC channel implementation in CFML
Install / Use
/learn @danylokravchenko/CfchannelREADME
cfchannel implementation in CFML
This module introduces MPSC channels for CFML.
Authors
Developed by Danylo Kravchenko
- https://github.com/UndeadBigUnicorn
- kravchel16@gmail.com
Requirements
This package requires Lucee 5+.
Examples
The module provides API for using MPSC channels in CFML. Here's a simple example of usage:
// create new unbounded channel
var channel = new Channel();
var tx = channel.getSender();
var rx = channel.getReceiver();
// since it MPSC channels, it is possible to clone sender
var clonedTx = tx.clone();
// send values into the channel
tx.send("a");
clonedTx.send("b");
// receive values
assert(rx.recv(), "a");
assert(rx.recv(), "b");
// next call of rx.recv() will block a current thread until new values will be send into the channel
// rx.recv();
Sender part of the channel could be closed and receiver is able to handle such cases. See the example below
var channel = new Channel();
var tx = channel.getSender();
var rx = channel.getReceiver();
// close sender part
tx.close();
// receiver returns null if there are 0 senders available
assert(isNull(rx.recv()));
MPSC channels are created for concurrent usage and code below show simple example:
var channel = new Channel();
var tx = channel.getSender();
var rx = channel.getReceiver();
// create new thread to send values
thread action="run" name="#CreateUUID()#" tx = "#tx#" {
for (var i = 0; i < 5; i++) {
tx.send(i);
}
}
// create new thread to receive values
thread action="run" name="#CreateUUID()#" rx = "#rx#" {
// execute a function for each item in the channel
rx.forEach((item) => WriteLog(type="information", text="#item#"));
}
ColdBox module example:
// Inject cfchannel module
property name="cfchannel" inject="cfchannel@cfchannel";
var channel = cfchannel.init();
var sender = channel.getSender();
// ...
CommandBox Compatible
Installation
This CF module can be installed as standalone or as a ColdBox Module. Either approach requires a simple CommandBox command:
box install cfchannel
Then follow either the standalone or module instructions below.
Standalone
This wrapper will be installed into a directory called cfchannel and then can be instantiated via new cfchannel.Channel().
ColdBox Module
This package also is a ColdBox module as well.
Then you can leverage the CFC via the injection DSL: cfchannel@cfchannel"
Useful Links
- https://en.wikipedia.org/wiki/Channel_(programming)
Related Skills
node-connect
339.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.9kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
339.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
83.9kCommit, push, and open a PR
