Created
February 15, 2015 11:18
-
-
Save yannick/ae4cd3727de49a07b84f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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