Created
April 13, 2015 20:25
-
-
Save yannick/98c94cb6530d8aabd420 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 vibe.http.client; | |
| import vibe.stream.operations : readAllUTF8; | |
| import vibe.http.common : HTTPMethod; | |
| import vibe.core.concurrency; | |
| import vibe.core.core; | |
| import std.datetime; | |
| shared static Task dbTask; | |
| void fetcher(Task dbTask){ | |
| auto url = "http://unicodesnowmanforyou.com/"; | |
| auto response = requestHTTP(url, | |
| (scope r) { | |
| r.method = HTTPMethod.GET; | |
| r.headers["User-Agent"] = "☃"; | |
| } | |
| ); | |
| string bdy = response.bodyReader.readAllUTF8(); | |
| dbTask.send( bdy ); | |
| } | |
| void db() | |
| { | |
| dbTask = Task.getThis(); | |
| writeln("db started"); | |
| while(true) { | |
| string dta = receiveOnly!string(); | |
| writeln(dta); | |
| } | |
| } | |
| shared static this() | |
| { | |
| runWorkerTask(&db); | |
| sleep(1.seconds); | |
| //start all workers | |
| runWorkerTask(&fetcher, dbTask); | |
| sleep(5.seconds); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment