Skip to content

Instantly share code, notes, and snippets.

@gramki
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save gramki/9721693 to your computer and use it in GitHub Desktop.

Select an option

Save gramki/9721693 to your computer and use it in GitHub Desktop.
Pseudo code for single threaded HTTPServer using async..await symantics
public class HTTPController {
private var server = new HTTPServer();
public async void Start() {
try {
while(true) {
server.listen(8080);
var request = await server.nextRequest();
if(request.getURL().matches("^/tweeets")) {
SendTweets(request);
} else {
request.send(404);
}
}
}catch(Exception) {
}
}
public async void SendTweets(HttpRequest request) {
var userID = request.getParameter("userID");
var page = await Twitter.getTweets(userID);
request.send(JSON.stringify(page));
request.end();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment