close() procedure should not raise, otherwise its impossible to cleanup.
This commit is contained in:
parent
0cb6840f03
commit
ac8b11d6ca
|
@ -186,27 +186,3 @@ proc newBoundedStreamWriter*(wsource: AsyncStreamWriter,
|
||||||
var res = BoundedStreamWriter(boundSize: boundSize)
|
var res = BoundedStreamWriter(boundSize: boundSize)
|
||||||
res.init(wsource, queueSize)
|
res.init(wsource, queueSize)
|
||||||
res
|
res
|
||||||
|
|
||||||
proc close*(rw: BoundedStreamRW) =
|
|
||||||
## Close and frees resources of stream ``rw``.
|
|
||||||
##
|
|
||||||
## Note close() procedure is not completed immediately.
|
|
||||||
if rw.closed():
|
|
||||||
raise newAsyncStreamIncorrectError("Stream is already closed!")
|
|
||||||
# We do not want to raise one more IncompleteError if it was already raised
|
|
||||||
# by one of the read()/write() primitives.
|
|
||||||
if rw.state != AsyncStreamState.Error:
|
|
||||||
if rw.bytesLeft() != 0'u64:
|
|
||||||
raise newBoundedStreamIncompleteError()
|
|
||||||
when rw is BoundedStreamReader:
|
|
||||||
cast[AsyncStreamReader](rw).close()
|
|
||||||
elif rw is BoundedStreamWriter:
|
|
||||||
cast[AsyncStreamWriter](rw).close()
|
|
||||||
|
|
||||||
proc closeWait*(rw: BoundedStreamRW): Future[void] =
|
|
||||||
## Close and frees resources of stream ``rw``.
|
|
||||||
rw.close()
|
|
||||||
when rw is BoundedStreamReader:
|
|
||||||
cast[AsyncStreamReader](rw).join()
|
|
||||||
elif rw is BoundedStreamWriter:
|
|
||||||
cast[AsyncStreamWriter](rw).join()
|
|
||||||
|
|
|
@ -715,19 +715,6 @@ suite "BoundedStream test suite":
|
||||||
except BoundedStreamIncompleteError:
|
except BoundedStreamIncompleteError:
|
||||||
clientRes = true
|
clientRes = true
|
||||||
await wbstream.closeWait()
|
await wbstream.closeWait()
|
||||||
elif test == 3:
|
|
||||||
for i in 0 ..< 10:
|
|
||||||
await wbstream.write(messagePart)
|
|
||||||
await wbstream.finish()
|
|
||||||
await wbstream.closeWait()
|
|
||||||
clientRes = true
|
|
||||||
elif test == 4:
|
|
||||||
for i in 0 ..< 9:
|
|
||||||
await wbstream.write(messagePart)
|
|
||||||
try:
|
|
||||||
await wbstream.closeWait()
|
|
||||||
except BoundedStreamIncompleteError:
|
|
||||||
clientRes = true
|
|
||||||
|
|
||||||
await wstream.closeWait()
|
await wstream.closeWait()
|
||||||
await transp.closeWait()
|
await transp.closeWait()
|
||||||
|
@ -755,18 +742,6 @@ suite "BoundedStream test suite":
|
||||||
except BoundedStreamIncompleteError:
|
except BoundedStreamIncompleteError:
|
||||||
res = true
|
res = true
|
||||||
await rbstream.closeWait()
|
await rbstream.closeWait()
|
||||||
elif test == 3:
|
|
||||||
let response {.used.} = await rbstream.read(int(size) - 1)
|
|
||||||
try:
|
|
||||||
await rbstream.closeWait()
|
|
||||||
except BoundedStreamIncompleteError:
|
|
||||||
res = true
|
|
||||||
elif test == 4:
|
|
||||||
try:
|
|
||||||
let response {.used.} = await rbstream.read()
|
|
||||||
except BoundedStreamIncompleteError:
|
|
||||||
res = true
|
|
||||||
await rbstream.closeWait()
|
|
||||||
|
|
||||||
await rstream.closeWait()
|
await rstream.closeWait()
|
||||||
await conn.closeWait()
|
await conn.closeWait()
|
||||||
|
@ -780,7 +755,3 @@ suite "BoundedStream test suite":
|
||||||
check waitFor(boundedTest(address, 1, item)) == true
|
check waitFor(boundedTest(address, 1, item)) == true
|
||||||
test "BoundedStream incomplete test [" & $item & "]":
|
test "BoundedStream incomplete test [" & $item & "]":
|
||||||
check waitFor(boundedTest(address, 2, item)) == true
|
check waitFor(boundedTest(address, 2, item)) == true
|
||||||
test "BoundedStream read() close test [" & $item & "]":
|
|
||||||
check waitFor(boundedTest(address, 3, item)) == true
|
|
||||||
test "BoundedStream write() close test [" & $item & "]":
|
|
||||||
check waitFor(boundedTest(address, 4, item)) == true
|
|
||||||
|
|
Loading…
Reference in New Issue