Download the PHP package ajayvohra2005/hack-promises without Composer

On this page you can find all versions of the php package ajayvohra2005/hack-promises. 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 hack-promises

Hack Promises

This project provides Promises/A+ implementation in Hack.

Overview

Key features

Requirements

HHVM 4.128 and above.

Installation

To use this package,

    composer require ajayvohra2005/hack-promises

Running tests

After installation, run the following command in the root directory of this repository:

    ./vendor/bin/hacktest tests/

License

This project is made available under the MIT License (MIT). Please see LICENSE file in this project for more information.

Tutorial

A promise represents the result of the resolution of an asynchronous operation, and the side-effects associated with the resolution.

Resolving a promise

Resolving a promise means that a promise is either fulfilled with a value or rejected with a reason. Resolving a promises triggers callbacks registered with the promises's then method. These callbacks are triggered only once and in the order in which they were added. When a callback is triggered, it is added to a global task queue. When the global task queue is , the tasks on the queue are removed and executed in the order they were added to the queue.

Global task queue

The global task queue can be as needed, or in an event loop. By default, the global task queue is run implicitly once prior to the program shutdown. The global task queue can be run explictily as shown below:

  HackPromises\TaskQueue::globalTaskQueue()->run();

Callbacks

Callbacks are registered with a promise by calling the then method of the promise, and by providing optional $onFulfilled and $onRejected functions, whereby the functions must be of type .

When you register callbacks with a promise by calling the method, it always returns a new promise. This can be used to create a chain of promises. The next promise in the chain is invoked with the resolved value of the previous promise in the chain. A promise in the chain is fulfilled only when the previous promise has been fulfilled.

Quick example

Below we show a quick start example that illustrates the concepts discussed so far:

Promise rejection

When a promise is rejected, the $onRejected callbacks are invoked with the rejection reason, as shown in the example below:

Rejection forwarding

If an exception is thrown in an $onRejected callback, subsequent $onRejected callbacks are invoked with the thrown exception as the reason.

If an exception is not thrown in a $onRejected callback and the callback does not return a rejected promise, downstream $onFulfilled callbacks are invoked using the value returned from the $onRejected callback, as shown in the example below:

Synchronous wait

You can resolve a promise synchronously by caling the method on a promise.

Calling the method of a promise invokes the wait function provided to the promise, and implicitly runs the global task queue. An example showing the use of the method is shown below:

If an exception is encountered while invoking the wait function of a promise, the promise is rejected with the exception and the exception is thrown. Calling wait method of a promise that has been fulfilled will not trigger the wait function. It will simply return the previously resolved value

Calling wait method on a promise that has been rejected will throw an exception. If the rejection reason is an instance of \Exception the reason is thrown. Otherwise, a HackPromises\RejectionException is thrown and the reason can be obtained by calling the getReason method of the exception.

Unwrapping a promise

When you call the method without an argument, or with the argument , it unwraps the promiose. Unwrapping the promise returns the value of the promise if it was fulfilled, or throws an exception if the promise was rejected. You can force a promise to resolve but not unwrap by passing false to the wait method of the promise, as shown in the example below:

When unwrapping a promise, the resolved value of the promise will be waited upon until the unwrapped value is not a promise. This means that if you resolve promise A with a promise B and unwrap promise A, the value returned by the wait function will be the result of resolving promise B, as shown in the example below;

Synchronous cancel

You can cancel a promise that has not yet been fulfilled synchronously using the cancel() method of a promise.

API classes

Promise

For the base case, you can use class to create a promise.

If you want to resolve the promise asynchronosuly and invoke the registerd callbacks, you can create the without any arguments to the constructor.

If you want be able to synchronously resolve or cancel the , pass the wait and cancel functions to the constructor.

Wait function

The wait function must be of type . The wait function provided to a constructor is invoked when the method of the is called. The wait function must resolve the by calling the function passed to it as an argument, or throw an exception.

Cancel function

When creating a you can provide an optional cancel function of type , which is invoked by the promise if you call the method of the promise. The cancel function may optionally reject the promise by invoking the function passed to it as an argument.

FulfilledPromise

The class object is fulfilled on construction.

RejectedPromise

The class object is rejected on construction.

IteratorPromise

The class creates an aggregated promise that iterates over an iterator of promises, or values, and triggers callback functions in the process. Use to create an iterator for a or a .

GeneratorPromise

The class wraps a generator that yields values, or promises.

Create

The class provides helper methods.

Acknowledgements

This project is inspired by Guzzle Promises. However, it has signficant differences in API and implementation, owing to the language and best-practices requirements of Hack.


All versions of hack-promises with dependencies

PHP Build Version
Package Version
Requires hhvm Version ^4.128
hhvm/hhvm-autoload Version ^3.3
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 ajayvohra2005/hack-promises contains the following files

Loading the files please wait ....