Edit: I was reading more bytes then available in t...
# javascript
e
Edit: I was reading more bytes then available in the Node socket buffer, thus I was never completing the job Anyone ever got a problem where a coroutine is just stuck at a return statement?
Copy code
private suspend fun readUnsignedInt(): Number {
  val buffer = read(4) ?: throw IllegalStateException("Expected 4 bytes to be available")
  val number = buffer.readUInt32BE(0)
  println(number)
  return number
}
I can see the number printed to the console, and then nothing, stuck forever.
a
Seems like a bug inside the Node.js wrappers. Could you please create a ticket in youtrack and assign it on me?
e
@Artem Kobzar what was happening is this. I'm reading n bytes from the TCP
net.Socket
Copy code
socket.read(nBytes)
If
nBytes
is greater than
socket.readableLength
,
read
returns null. What I was doing was:
Copy code
val buffer = socket.read(nBytes) as? Buffer?

if (buffer != null) {
  continuation.resume(buffer)
}
Are you sure it's a bug on your side? This seems more an error on my side
a
Oh, in this case, yes, the bug is on your side.