remove sleepAsync for synchronization
This commit is contained in:
parent
53e163abf2
commit
f4e9bc8bfb
|
@ -103,14 +103,14 @@ proc pushTo*(s: BufferStream, data: seq[byte]) {.async.} =
|
||||||
## is preserved.
|
## is preserved.
|
||||||
##
|
##
|
||||||
|
|
||||||
|
try:
|
||||||
await s.lock.acquire()
|
await s.lock.acquire()
|
||||||
var index = 0
|
var index = 0
|
||||||
while true:
|
while true:
|
||||||
|
|
||||||
# give readers a chance free up the buffer
|
# give readers a chance free up the buffer
|
||||||
# it it's full.
|
# it it's full.
|
||||||
if s.readBuf.len >= s.maxSize:
|
if s.readBuf.len >= s.maxSize:
|
||||||
await sleepAsync(10.millis)
|
await sleepAsync(1.millis)
|
||||||
|
|
||||||
while index < data.len and s.readBuf.len < s.maxSize:
|
while index < data.len and s.readBuf.len < s.maxSize:
|
||||||
s.readBuf.addLast(data[index])
|
s.readBuf.addLast(data[index])
|
||||||
|
@ -121,11 +121,13 @@ proc pushTo*(s: BufferStream, data: seq[byte]) {.async.} =
|
||||||
s.readReqs.popFirst().complete()
|
s.readReqs.popFirst().complete()
|
||||||
|
|
||||||
if index >= data.len:
|
if index >= data.len:
|
||||||
break
|
return
|
||||||
|
|
||||||
# if we couldn't transfer all the data to the
|
# if we couldn't transfer all the data to the
|
||||||
# internal buf wait on a read event
|
# internal buf wait on a read event
|
||||||
await s.dataReadEvent.wait()
|
await s.dataReadEvent.wait()
|
||||||
|
s.dataReadEvent.clear()
|
||||||
|
finally:
|
||||||
s.lock.release()
|
s.lock.release()
|
||||||
|
|
||||||
method read*(s: BufferStream, n = -1): Future[seq[byte]] {.async.} =
|
method read*(s: BufferStream, n = -1): Future[seq[byte]] {.async.} =
|
||||||
|
|
Loading…
Reference in New Issue