Skip to content

Instantly share code, notes, and snippets.

@yannick
Created February 15, 2015 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yannick/ae4cd3727de49a07b84f to your computer and use it in GitHub Desktop.
Save yannick/ae4cd3727de49a07b84f to your computer and use it in GitHub Desktop.
import std.stdio;
import leveldb;
import vibe.core.concurrency;
import vibe.core.core;
import std.datetime;
shared static int counter;
shared static Task dbTask;
struct Query{ Task sender; string msg;}
static void dbFunc(){
dbTask = Task.getThis();
while(true){
receive(
(Query q){
core.atomic.atomicOp!"+="(counter, 1) ;
q.sender.send("result");
}
);
}
}
static void workerFunc(Task db){
while(true){
db.send(Query(Task.getThis(), "test"));
receive( (string astring) {
//writeln("received string", astring);
});
}
}
shared static this()
{
runWorkerTask({
setTimer(1.seconds, {
writeln("counter: ", counter);
counter = 0;
stdout.flush();
}, true);
});
runWorkerTask(&dbFunc);
sleep(1.seconds);
runWorkerTaskDist(&workerFunc, dbTask);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment