Last active
August 29, 2015 14:15
-
-
Save davebshow/f5668437398afa749f37 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 asyncio | |
import json | |
from tornado import escape, gen | |
from tornado.web import RequestHandler, Application, url | |
from tornado.platform.asyncio import AsyncIOMainLoop | |
from gizmo import AsyncGremlinClient | |
class GremlinHandler(RequestHandler): | |
@gen.coroutine | |
def get(self): | |
gc = AsyncGremlinClient(uri='ws://localhost:8182/') | |
consumer = lambda x: x["result"]["data"] | |
yield from gc.task(gc.send_receive, "g.V().values(n)", | |
bindings={"n": "name"}, consumer=consumer) | |
while not gc.messages.empty(): | |
message = yield from gc.messages.get() | |
message = json.dumps(message) | |
self.write(message) | |
def make_app(): | |
return Application([ | |
url(r"/", GremlinHandler), | |
]) | |
def main(): | |
app = make_app() | |
# Must create IOLoop before calling app.listen. | |
AsyncIOMainLoop().install() | |
app.listen(8888) | |
asyncio.get_event_loop().run_forever() | |
if __name__ == '__main__': | |
print("Starting server at http://localhost:8888/") | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment