Skip to content

Instantly share code, notes, and snippets.

@davebshow
Created October 7, 2015 23:30
Show Gist options
  • Save davebshow/539cd4c838934a7d2375 to your computer and use it in GitHub Desktop.
Save davebshow/539cd4c838934a7d2375 to your computer and use it in GitHub Desktop.
import uuid
from tornado.concurrent import Future
from tornado.websocket import websocket_connect
class GremlinResponseStream:
def __init__(self, conn):
self._conn = conn
@asyncio.coroutine
def read(self):
pass
@asyncio.coroutine
def submit(gremlin, *,
url='http://localhost:8182/',
bindings=None,
lang="gremlin-groovy",
rebindings=None,
op="eval",
processor="",
timeout=None,
session=None,
loop=None,
username="",
password=""):
message = {
"requestId": str(uuid.uuid4()),
"op": op,
"processor": processor,
"args": {
"gremlin": gremlin,
"bindings": bindings,
"language": lang,
"rebindings": rebindings
}
}
future = Future()
future_conn = websocket_connect(url)
def send_message(conn):
conn.write_message(message, callback=lambda: future.set_result(conn))
future_conn.add_done_callback(send_message)
return future
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment