kameloso.thread

Structures and functions related to message passing, threads and Fibers.

Members

Classes

Boxed
class Boxed(T)

A payload of type T wrapped in a class implementing the Sendable interface. Used to box values for sending via the message bus.

CarryingFiber
class CarryingFiber(T)

A Fiber carrying a payload of type T, along with some metadata.

Functions

boxed
shared(Sendable) boxed(T payload)

Constructor function to create a shared Boxed with an unqualified template type.

carryingFiber
auto carryingFiber(FnOrDg fnOrDg, T payload, Args args, string caller)

Convenience function creating a new CarryingFiber while inferring the payload type T from the passed payload argument.

getQuitMessage
auto getQuitMessage(IRCPlugin[] plugins)

Iterates the messages and priorityMessages arrays of each plugin. If a quit message is found, its content is returned.

interruptibleSleep
void interruptibleSleep(Duration dur, bool* abort)

Sleep in small periods, checking the passed abort flag in between to see if we should break and return.

pthread_setname_np
int pthread_setname_np(pthread_t , char* )

Prototype to allow linking to pthread's function for naming threads.

setThreadName
void setThreadName(string name)

Sets the thread name of the current thread, so they will show up named in process managers (like top).

Interfaces

Sendable
interface Sendable

Interface for a message sendable through the message bus.

Structs

ScheduledDelegate
struct ScheduledDelegate

A delegate paired with a long UNIX timestamp.

ScheduledFiber
struct ScheduledFiber

A Fiber paired with a long UNIX timestamp.

ThreadMessage
struct ThreadMessage

Collection of static functions used to construct thread messages, for passing information of different kinds yet still as one type, to be able to store them in arrays for later processing.

Examples

plugin.state.messages ~= ThreadMessage.sendline("Message to send to server");
plugin.state.priorityMessages ~= ThreadMessage.pong("irc.libera.chat");
plugin.state.messages ~= ThreadMessage.askToWriteln("writeln this for me please");
plugin.state.messages ~= ThreadMessage.busMessage("header", boxed("payload"));

auto fiber = new CarryingFiber!string(&someDelegate, BufferSize.fiberStack);
fiber.payload = "This string is carried by the fiber and can be accessed from within it";
fiber.call();
fiber.payload = "You can change it in between calls to pass information to it";
fiber.call();

// As such we can make fibers act like they're taking new arguments each call
auto fiber2 = new CarryingFiber!IRCEvent(&otherDelegate, BufferSize.fiberStack);
fiber2.payload = newIncomingIRCEvent;
fiber2.call();
// [...]
fiber2.payload = evenNewerIncomingIRCEvent;
fiber2.call();

See Also

Meta