SkillAgentSearch skills...

Cfchannel

MPSC channel implementation in CFML

Install / Use

/learn @danylokravchenko/Cfchannel
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

cfchannel implementation in CFML


This module introduces MPSC channels for CFML.

cfmlbadges cfmlbadges cfmlbadges cfmlbadges cfmlbadges

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

View on GitHub
GitHub Stars4
CategoryDevelopment
Updated1y ago
Forks0

Languages

ColdFusion

Security Score

70/100

Audited on Aug 25, 2024

No findings