Examples
This is a list of further examples that show off various details of ThreadButler.
You can also find them in their github folder. Their filenames have the ex_
prefix.
Async
ThreadButlers own eventLoop comes with simple support for asynchronous handlers.
Just annotate your handler with {.async.} and the code generated by generateRouting
will adjust to account for that.
Custom Event Loops
ThreadButler allows replacing the default event-loop it uses for ThreadServers with your own.
Therefore, if you need to supply your own, e.g. because you need to run the event-loop from a GUI framework on that thread, you can do so.
Just overload the runServerLoop
proc.
Tasks
ThreadButler itself does provide any threadpools. However, you can initialize and destroy any threadpool implementation you want using its startUp/shutDown events.
To that end, threadButler provides convenience events to quickly set up:
Keep in mind that the threadServer macro does not emit the handler procs defined inside of it.
This is done by prepareServers
. So if a handler spawns a task proc, that task proc must be available where you call prepareServers
.
No Server
ThreadButler can be useful even without running a dedicated thread as a server.
This example uses ThreadButlers code-generation to just set up a threadpool that sends messages back and handling those automatically. No threadServer is spawned, just the main-thread and a task-pool.