event-pipe ~main

Event Pipe: Event and message passing system developed for Fluid


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

event-pipe

This package is an event and message passing system developed for Fluid.

import event_pipe;

Subscribers & Publishers

A Subscriber receives and processes data received from another class. It is more-or-less equivalent to a delegate.

interface Subscriber(Ts...) {
    void opCall(Ts args);
}

A Publisher emits data through Subscriber objects.

interface Publisher(Outputs...) {
    void subscribe(Subscriber!Output subscriber);
}

Additionally, Publisher offers a shorthand then function that accepts a delegate:

publisher
    .then((int input) => input + 1);

Under the hood, then converts the delegate into a Subscriber object (this object is always a Pipe).

Pipes

A Pipe is a basic implementation of both Subscriber and Publisher. It runs a function on the input and "pipes" the result to a publisher.

/// Pipe as a Subscriber:
unittest {
    auto sub = pipe((string input) {
        return "Hello, " ~ input ~ "!";
    });
    sub.then((string input) {
        writeln(input);
    });
    sub("World");  // Outputs "Hello, World!"
}

Chaining

Any instance of then implicitly creates a Pipe, allowing for chaining. If a delegate passed into then returns a Publisher

unittest {
    auto start = pipe(() => "Hello, ");
    auto setName = pipe((string input) => input);
    
    start
        // Take `prefix` and wait for setName
        .then((string prefix) => setName
            .then((string name) => prefix ~ name))

        // Having concatenated the two, write them out
        .then((string result) => writeln(result));

    start();
    setName("Night");
}

Events

To distribute events to a set of subscribers, one can use the Event struct.

unittest {
    Event!string event;
    event ~= pipe((string input) => writeln("Hello, ", input));
    event ~= pipe((string input) => writeln("Goodnight, ", input));
    event("World");
}

Documentation

For more information see documentation inside the code.

Authors:
  • Artha
Dependencies:
none
Versions:
1.0.0-rc.1 2025-Dec-20
~main 2025-Dec-20
Show all 2 versions
Download Stats:
  • 2 downloads today

  • 174 downloads this week

  • 174 downloads this month

  • 174 downloads total

Score:
1.0
Short URL:
event-pipe.dub.pm