Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bufferstream] readers would be canceled on stream close. #84

Closed
cheatfate opened this issue Feb 18, 2020 · 3 comments
Closed

[bufferstream] readers would be canceled on stream close. #84

cheatfate opened this issue Feb 18, 2020 · 3 comments

Comments

@cheatfate
Copy link
Contributor

import chronos
import bufferstream

proc testReadCancellation(): Future[bool] {.async.} =
  var stream = newBufferStream()
  proc readMessage1(s: BufferStream): Future[seq[byte]] {.async.} =
    result = await s.read(10)
  proc readMessage2(s: BufferStream): Future[seq[byte]] {.async.} =
    var res = await readMessage1(s)
    res.add(@[0x00'u8, 0x00'u8])
  proc readMessage3(s: BufferStream): Future[seq[byte]] {.async.} =
    var res = await readMessage2(s)
    res.add(@[0x01'u8, 0x01'u8])

  var fut = stream.readMessage3()
  await stream.close()
  var c = await fut

when isMainModule:
  echo waitFor(testReadCancellation())

This code raises CancelledError, but it should not.

@dryajov
Copy link
Contributor

dryajov commented Feb 18, 2020

This is by design, but perhaps we can raise an EOF instead of canceling the Future.

@cheatfate
Copy link
Contributor Author

Raising one simple EOF is not enough, because different primitives has different behavior, for example read() should just returned all the data it gets before EOF received, while readUntil() should raise IncompleteError.

@arnetheduck
Copy link
Contributor

obsolete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants