←back to thread

116 points doekenorg | 1 comments | | HN request time: 0.209s | source
Show context
donatj ◴[] No.44498833[source]
I have read much about Fibers since they were introduced and have never come up with a real use case.

All the examples I find are like the trivial ones here where it just feels like instead of jamming a bunch of code into a single messy function that yields, you'd be better off particularly from a static analysis standpoint just having ordered method calls or chained callables where each step returns the next step as a callable.

I've yet to see a use case where I can't come up with a safer way to do it without Fibers, but I would love if someone could enlighten me because I feel like I am absolutely missing something.

replies(4): >>44499326 #>>44499413 #>>44499430 #>>44502332 #
danogentili ◴[] No.44499413[source]
Fibers are incredibly powerful, as they can be used to implement seamless go-like concurrency with async, colorless functions.

They were added to PHP by the maintainers of amphp (https://amphp.org), which is the best library for async PHP out there, providing a clean, object-oriented and async API for files, databases and everything that can make use of async I/O.

replies(1): >>44499581 #
donatj ◴[] No.44499581[source]
A fiber is a colored function. It's a different color than an async function, but it's not blindly swapable for a regular function.
replies(1): >>44508267 #
1. danogentili ◴[] No.44508267[source]
Async functions based on PHP fibers are explicitly uncolored, they do not require any special keywords to be invoked, and are explicitly swappable with any regular functions.