Streaming File Input in libuv

In the POSIX model, we could treat pipes and files more or less interchangeably and use the same blocking I/O patterns, such as fgets and println, with either one. But in libuv, files are a totally different beast from anything else we’ve encountered. Because ordinary disk files are not pollable for readiness in Linux, there’s no way to read or write from a file without the risk of blocking.

libuv provides an alternative: a background thread pool for running UNIX-style system calls, where blocking calls can run without interfering with our event loop. These system calls are not modeled as streams, though. Each call is one-off, which means we’ll need to do a little extra work to create something that fits our

Get Modern Systems Programming with Scala Native now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.