Last active
August 29, 2015 13:57
-
-
Save gramki/9721693 to your computer and use it in GitHub Desktop.
Pseudo code for single threaded HTTPServer using async..await symantics
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
| 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