Skip to content

Instantly share code, notes, and snippets.

@vegansk
Created August 25, 2016 10:02
Show Gist options
  • Save vegansk/d141d5ce956b61c6d314aac881527250 to your computer and use it in GitHub Desktop.
Save vegansk/d141d5ce956b61c6d314aac881527250 to your computer and use it in GitHub Desktop.
import asyncdispatch, asyncnet
type
AsyncStream* = ref AsyncStreamObj
AsyncStreamObj* = object of RootObj
closeImpl*: proc (s: AsyncStream)
atEndImpl*: proc (s: AsyncStream): bool
setPositionImpl*: proc (s: AsyncStream; pos: int64)
getPositionImpl*: proc (s: AsyncStream): int64
readDataImpl*: proc (s: AsyncStream; size: int): Future[string] {.tags: [ReadIOEffect].}
writeDataImpl*: proc (s: AsyncStream; data: string): Future[void] {.tags: [WriteIOEffect].}
flushImpl*: proc (s: AsyncStream): Future[void]
####################################################################################################
# AsyncStream
proc readChar*(s: AsyncStream): Future[char] {.async.} =
let data = await s.readDataImpl(s, 1)
result = if data.len == 0: '\0' else: data[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment