Skip to content

Instantly share code, notes, and snippets.

@DmitryOlshansky
Created January 31, 2018 15:04
Show Gist options
  • Save DmitryOlshansky/873a198eaf27061f00cdea776884cca5 to your computer and use it in GitHub Desktop.
Save DmitryOlshansky/873a198eaf27061f00cdea776884cca5 to your computer and use it in GitHub Desktop.
Out of band signal
// Consider that we spin up one of these guys per file
// the idea is that we can interrupt this fiber by sending Control message
// that will be processed out of bounds
void logFileProcessor(Stream!Control controlPlane, File inp)
{
bool done = false;
auto source = inp.byLine; //
while(!done){
multiplex( // pick one of sources that are ready and execute branches
controlPlane, {
// controlPlane is ready - assume this means termination
done = true;
}
source, {
// source is ready
if (source.empty) done = true;
else {
auto line = source.front;
scope(exit) source.popFront();
.... // do things with line
}
}
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment