Skip to content

Instantly share code, notes, and snippets.

@yannick
Created April 13, 2015 20:25
Show Gist options
  • Select an option

  • Save yannick/98c94cb6530d8aabd420 to your computer and use it in GitHub Desktop.

Select an option

Save yannick/98c94cb6530d8aabd420 to your computer and use it in GitHub Desktop.
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