← 所有消息

Three jobs, one wall clock

await() runs several app targets at once and returns when the last one finishes, so a route that does three independent things takes as long as the slowest rather than the sum.

$out = await (
    invoice: ['billing::render', $id],
    thumb:   ['media::resize', $id],
    mail:    ['notify::send', $id],
)

Each job is a target the app already has, named so the result comes back under that name. Nothing about the called code changes; a method that works in a route works here.

Where the work runs depends on what is available. With the daemon present, the jobs go into the worker pool and land on processes that are already booted, which is the whole reason the pool exists. Without it, await() opens one-shot CLI processes instead and reads their pipes. Same call, same results, different cost, and an app does not have to know which world it is in.

The honest limit is that these are separate processes. There is no shared memory, so a job returns its result rather than mutating something the caller can see, and the ordering between jobs is not yours to control. That is a fair trade for the thing it buys: fan-out that is one function call rather than a queue, a worker script and a table to poll.

The related pieces sit next to it. phlo_async() fires one target and returns immediately, and chunk() streams progress back to a page while the work continues.

Engine 1.0. See the Daemon chapter.

我们使用必要的cookie来使该网站正常工作。在您的许可下,我们还使用分析工具来改善网站。