<@U0BLPSJAK> What is this reference to `copyToSusp...
# ktor
r
@Deactivated User What is this reference to
copyToSuspend
@ https://ktor.io/servers/uploads.html ? I suspect that should just be
copyTo
right?
d
Well. It is just an extension method defined below in that page too. I guess I added the suspend suffix to make it clear that was asynchronous. But I probably i could just remove that suffix
r
Ah, I didn't even see that... I thought it wasn't really possible to create a suspending function reading/writing streams, as streams are always blocking. There was some discussion about this in #coroutines .
i.e. there is no way to guarantee that that call to
out.write(buffer, 0, bytes)
will not block.
d
Actually, that extension method does the blocking calls in another thread. So yes, it is blocking, but it blocks another thread.
r
Via the
ioCoroutineDispatcher
?
d
Yes. That dispatcher uses a thread pool just for blocking I/O
r
Cool. I didn't realize that was already available -- I thought it was still being worked on.
d
And it makes copy in chunks. So after each suspension, for each thread in that dispatcher, it can multiplex other synchronous reads
r
Ah, I see
IOCoroutineDispatcher
is part of ktor, not the couroutines lib.
Cool stuff, thanks.
­čĹŹ 1
yes