Download the PHP package sof3/await-generator without Composer

On this page you can find all versions of the php package sof3/await-generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package await-generator

Eng | 简

await-generator

Build Status Codecov

A library to use async/await pattern in PHP.

Documentation

Read the await-generator tutorial for an introduction from generators and traditional async callbacks to await-generator.

Why await-generator?

Traditional async programming requires callbacks, which leads to spaghetti code known as "callback hell":

Click to reveal example callback hell

With await-generator, this is simplified into:

Can I maintain backward compatibility?

Yes, await-generator does not impose any restrictions on your existing API. You can wrap all await-generator calls as internal implementation detail, although you are strongly encouraged to expose the generator functions directly.

await-generator starts an await context with the Await::f2c method, with which you can adapt into the usual callback syntax:

Or if you want to handle errors too:

You can continue to call functions implemented as callback style using the Await::promise method (similar to new Promise in JS):

Why not await-generator

await-generator has a few common pitfalls:

While these pitfalls cause some trouble, await-generator style is still much less bug-prone than a callback hell.

But what about fibers?

This might be a subjective comment, but I do not prefer fibers for a few reasons:

Explicit suspension in type signature

For example, it is easy to tell from the type signature that $channel->send($value): Generator<void> suspends until the value is sent and $channel->sendBuffered($value): void is a non-suspending method that returns immediately. Type signatures are often self-explanatory.

Of course, users could call sleep() anyway, but it is quite obvious to everyone that sleep() blocks the whole runtime (if they didn't already know, they will find out when the whole world stops).

Concurrent states

When a function suspends, many other things can happen. Indeed, calling a function allows the implementation to call any other functions which could modify your states anyway, but a sane, genuine implementation of e.g. an HTTP request wouldn't call functions that modify the private states of your library. But this assumption does not hold with fibers because the fiber is preempted and other fibers can still modify the private states. This means you have to check for possible changes in private properties every time you call any function that might be suspending.

On the other hand, using explicit await, it is obvious where exactly the suspension points are, and you only need to check for state mutations at the known suspension points.

Trapping suspension points

await-generator provides a feature called "trapping", which allows users to add pre-suspend and pre-resume hooks to a generator. This is simply achieved by adding an adapter to the generator, and does not even require explicit support from the await-generator runtime. This is currently not possible with fibers.


All versions of await-generator with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
ext-bcmath Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package sof3/await-generator contains the following files

Loading the files please wait ....