parent
a5be5303e3
commit
48880c6e4e
|
@ -442,11 +442,12 @@ proc all*[T](futs: varargs[Future[T]]): auto =
|
||||||
let totalFutures = len(futs)
|
let totalFutures = len(futs)
|
||||||
|
|
||||||
for fut in futs:
|
for fut in futs:
|
||||||
fut.addCallback proc (f: Future[T]) =
|
fut.addCallback proc (data: pointer) =
|
||||||
|
var fut = cast[FutureBase](data)
|
||||||
inc(completedFutures)
|
inc(completedFutures)
|
||||||
if not retFuture.finished:
|
if not retFuture.finished:
|
||||||
if f.failed:
|
if fut.failed:
|
||||||
retFuture.fail(f.error)
|
retFuture.fail(fut.error)
|
||||||
else:
|
else:
|
||||||
if completedFutures == totalFutures:
|
if completedFutures == totalFutures:
|
||||||
retFuture.complete()
|
retFuture.complete()
|
||||||
|
@ -464,14 +465,14 @@ proc all*[T](futs: varargs[Future[T]]): auto =
|
||||||
|
|
||||||
for i, fut in futs:
|
for i, fut in futs:
|
||||||
proc setCallback(i: int) =
|
proc setCallback(i: int) =
|
||||||
fut.addCallback proc (f: Future[T]) =
|
fut.addCallback proc (data: pointer) =
|
||||||
|
var fut = cast[Future[T]](data)
|
||||||
inc(completedFutures)
|
inc(completedFutures)
|
||||||
if not retFuture.finished:
|
if not retFuture.finished:
|
||||||
if f.failed:
|
if fut.failed:
|
||||||
retFuture.fail(f.error)
|
retFuture.fail(fut.error)
|
||||||
else:
|
else:
|
||||||
retValues[i] = f.read()
|
retValues[i] = fut.read()
|
||||||
|
|
||||||
if completedFutures == len(retValues):
|
if completedFutures == len(retValues):
|
||||||
retFuture.complete(retValues)
|
retFuture.complete(retValues)
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
import net, nativesockets, strutils
|
import net, nativesockets, strutils
|
||||||
import ../asyncloop
|
import ../asyncloop
|
||||||
|
|
||||||
|
export net
|
||||||
|
|
||||||
const
|
const
|
||||||
DefaultStreamBufferSize* = 4096 ## Default buffer size for stream
|
DefaultStreamBufferSize* = 4096 ## Default buffer size for stream
|
||||||
## transports
|
## transports
|
||||||
|
|
|
@ -798,8 +798,9 @@ proc createStreamServer*[T](host: TransportAddress,
|
||||||
result = createStreamServer(host, cbproc, flags, sock, backlog, bufferSize,
|
result = createStreamServer(host, cbproc, flags, sock, backlog, bufferSize,
|
||||||
cast[pointer](udata))
|
cast[pointer](udata))
|
||||||
|
|
||||||
proc getUserData*[T](server: StreamServer): ref T {.inline.} =
|
proc getUserData*[T](server: StreamServer): T {.inline.} =
|
||||||
result = cast[ref T](server.udata)
|
## Obtain user data stored in ``server`` object.
|
||||||
|
result = cast[T](server.udata)
|
||||||
|
|
||||||
proc write*(transp: StreamTransport, pbytes: pointer,
|
proc write*(transp: StreamTransport, pbytes: pointer,
|
||||||
nbytes: int): Future[int] =
|
nbytes: int): Future[int] =
|
||||||
|
|
Loading…
Reference in New Issue