Introducing: Conductor, a small library to coordinate work in a program

TL;DR: conductor is a new library I have been working on recently, check it out.

Why

I am planning to fully rework papero. In particular, the daemon that handles the synchronization of the local folders with the remote IMAP server. The use case that I care most should allow for a single daemon to handle multiple accounts at once, and to have maybe coordinated tasks lightly coupled. Currently, the whole thing uses a Elm-like architecture. It is working, but I don’t like it. Also, it limits the execution loop to run through one account at a time. I imagined then a system where a single goroutine receives commands, and dispatches them to the pool of workers that are in charge of the real work. The idea pushed me naturally towards the ergonomics of Context, where a for ... select loop is used to handle non-blocking interrupts.

Show it

The README is pretty verbose, and I encourage you to take a look. I also tried to be thorough in documenting it and provide some (hopefully useful) example.

Copy-pasting from the README

tagged := Tagged[string]()

// we listen on many different possible tags

for {
	select {
	case cmd := <-WithTag[string](tagged, "tag1").Cmd():
		// React to a command in the "tag1" branch
	case cmd := <-WithTag[string](tagged, "tag2").Cmd():
		// React to a command in the "tag2" branch
	case <-tagged.Done():
		// As for the Simple, also the Tagged is a Context
	}
}


// We may selectively send a command, again using the Send function

Send[string](tagged, "tag1")("doitnow")

// We may also send a broadcast command

Send[string](tagged)("allhands")

So what?

I will use it in my projects and hope to have a good time with it. If you would like to give it a shot, please do and feel free to report back any strangeness or inconvenience at:

blallo -|AT|- autistici.org