kameloso.thread

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

Members

Aliases

BusMessage
deprecated alias BusMessage = Boxed

Deprecated alias to Boxed.

sendable
deprecated alias sendable = boxed

Deprecated alias to boxed.

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.

Functions

boxed
shared(Sendable) boxed(T payload)

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

exhaustMessages
void exhaustMessages()

Exhausts the concurrency message mailbox.

interruptibleSleep
void interruptibleSleep(Duration dur, bool abort)

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

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

OutputRequest
struct OutputRequest

Embodies the notion of a request to output something to the local terminal.

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 stop std.concurrency.send from requiring so much compilation memory.

Examples

import std.concurrency;

mainThread.send(ThreadMessage.sendline("Message to send to server"));
mainThread.send(ThreadMessage.pong("irc.libera.chat"));
mainThread.send(OutputRequest(ThreadMessage.TerminalOutput.writeln, "writeln this for me please"));
mainThread.send(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