Skip to content

Instantly share code, notes, and snippets.

@niv

niv/twice.nim Secret

Created April 26, 2016 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niv/5e50fef3a33ba52cdfa6654822e80c7e to your computer and use it in GitHub Desktop.
Save niv/5e50fef3a33ba52cdfa6654822e80c7e to your computer and use it in GitHub Desktop.
proc redisCommand*(redis: Redis, command: seq[string]):
Future[RedisReply] {.async.} =
## Execute a redis command.
echo "command: ", command
await ( Future[void](redis.socketAvailable) )
doAssert(finished(redis.socketAvailable))
echo "cleaning"
FutureVar[void](redis.socketAvailable).clean()
doAssert(not finished(redis.socketAvailable))
redis.writeCommand(command)
result = await readResponse(redis)
echo "completing sockAvail on " & $command
redis.socketAvailable.complete()
command: @[GET, 0]
cleaning
completing sockAvail on @[GET, 0]
completing sockAvail on @[GET, 0]
Traceback (most recent call last)
Error: unhandled exception: An attempt was made to complete a Future more than once. Details:
Future ID: 2
Created in proc: redis.inflight(10.2.1.7:6379)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment