zorael / kameloso

IRC bot with Twitch support
Boost Software License 1.0
9 stars 3 forks source link

Flattened `ThreadMessage`s #119

Closed zorael closed 2 years ago

zorael commented 2 years ago

This refactors ThreadMessages from being uniquely typed (and thus instantiating an extra overload of std.concurrency.send each) to instead share a common type runtime-distinguished by a Type enum member. It cuts compilation memory requirements considerably.

mainThread.send(ThreadMessage.Pong(), service.state.server.address);
mainThread.send(ThreadMessage.Save());
mainThread.send(ThreadMessage.BusMessage, "admin", busMessage("reload"));

// ...becomes...

mainThread.send(ThreadMessage.pong(service.state.server.address));
mainThread.send(ThreadMessage.save());
mainThread.send(ThreadMessage.busMessage("admin", sendable("reload")));

Thus they share one std.concurrency.send!ThreadMessage instantiation, instead of one for each static struct nested in ThreadMessage. (Pong, Save, BusMessage, Sendline, Quit, Reload, PeekCommands, etc.)