Async functions ᴾᴴᴾ - chung-leong/zigar GitHub Wiki
JavaScript | PHP
A Zig function becomes an async function on the PHP side when it accepts a Promise as an argument. Instead of being returned, the return value will be passed to the promise struct’s resolve() method.
A Generator argument works in a similar manner. Its turns a Zig function into an async generator function on the PHP side. Instead of one value, multiple values are returned asynchronously to the caller through the struct's yield() method.
You can easily create async functions with the help of a work queue's promisify and asyncify methods.
No function "coloring"
Unlike in JavaScript, calling an async function in PHP does not require the use of a special keyword. Async functions work like regular functions.
When zigar.event_loop is set to "temporary", a new PHP fiber is spun up to handle redirected system calls and callback functions while the main fiber waits for the promise to resolve.
When it's set to "revolt", execution of the calling fiber is suspended, allowing Revolt to schedule other active fibers to run.
zigar.function.Promise | zigar.function.Generator | zigar.thread.WorkQueue