Sergey Zhuk: ReactPHP PromiseStream: From Promise To Stream And Vice Versa

Sergey Zhuk
has posted another article to his site covering functionality provided in ReactPHP. In this latest tutorial he covers the PromiseStream handling
of the library allowing for the translation from promise to stream (and back).

But, imagine that we have some client code that wants to process some data from a file. It doesn’t care about the streams, it only needs to receive the entire data from the file. With this approach, this code should be called inside the callback for the end event of the stream. So, the client code should now about streams, events, and callbacks. But sometimes it’s impossible.

Example code is included to illustrate the problem above and an answer is provided in the form of ReactPHP promises. This allows the data to move into the promise as the data is being read from the stream’s source. The tutorial goes on to talk about the functionality behind this transition including the buffer
method to create the promise with chunked data, the all
method to build the promise from the full data in the stream and the first
method that works with events on the stream. The article then covers the reverse, showing how to pull information from a promise and push it back out to a stream via the unwrapReadable
and unwrapWritable

PHPDeveloper稿源:PHPDeveloper (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 前端开发 » Sergey Zhuk: ReactPHP PromiseStream: From Promise To Stream And Vice Versa

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录