What is the best way to read files in an EventMachine-based app?

前端 未结 1 2002
情深已故
情深已故 2020-12-16 17:03

In order not to block the reactor I would like to read files asynchronously, but I\'ve found no obvious way of doing it using EventMachine. I\'ve tried a few different appro

相关标签:
1条回答
  • 2020-12-16 17:57

    EM.attach/watch cannot be used on files, as select/epoll on a disk-based file descriptor will always return readable.

    Ultimately, it depends on what you're trying to do. If it's a small file, just File.read it. If it is larger, you can read small chunks over time. For example, EM::FileStreamer does this to send large file over the network.

    Another common use-case is to tail a file and read in new contents when it changes. This can be achieved using EM.watch_file: http://github.com/jordansissel/eventmachine-tail

    0 讨论(0)
提交回复
热议问题