close() procedure should not raise, otherwise its impossible to cleanup.

This commit is contained in:
cheatfate 2021-01-20 17:08:16 +02:00 committed by zah
parent 0cb6840f03
commit ac8b11d6ca
2 changed files with 0 additions and 53 deletions

View File

@ -186,27 +186,3 @@ proc newBoundedStreamWriter*(wsource: AsyncStreamWriter,
var res = BoundedStreamWriter(boundSize: boundSize)
res.init(wsource, queueSize)
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()

View File

@ -715,19 +715,6 @@ suite "BoundedStream test suite":
except BoundedStreamIncompleteError:
clientRes = true
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 transp.closeWait()
@ -755,18 +742,6 @@ suite "BoundedStream test suite":
except BoundedStreamIncompleteError:
res = true
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 conn.closeWait()
@ -780,7 +755,3 @@ suite "BoundedStream test suite":
check waitFor(boundedTest(address, 1, item)) == true
test "BoundedStream incomplete test [" & $item & "]":
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