2017 © Pedro Peláez
 

library icicle

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

image

icicleio/icicle

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  • Friday, March 17, 2017
  • by Trowski
  • Repository
  • 74 Watchers
  • 1124 Stars
  • 56,127 Installations
  • PHP
  • 16 Dependents
  • 0 Suggesters
  • 44 Forks
  • 1 Open issues
  • 35 Versions
  • 4 % Grown

The README.md

Icicle is now deprecated in favor of Amp v2.0. This version is is currently under development, but close to release. The v2.0 branches are amp_v2 in all packages except the main Amp package, loop package, and postgres package, where v2.0 is the master branch., (*1)

Icicle

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques., (*2)

Icicle uses Coroutines built with Awaitables and Generators to facilitate writing asynchronous code using techniques normally used to write synchronous code, such as returning values and throwing exceptions, instead of using nested callbacks typically found in asynchronous code., (*3)

Build Status Coverage Status Semantic Version MIT License @icicleio on Twitter, (*4)

Library Components

  • Coroutines are interruptible functions for building asynchronous code using synchronous coding patterns and error handling.
  • Awaitables act as placeholders for future values of asynchronous operations. Awaitables can be yielded in coroutines to define interruption points. Callbacks registered with awaitables may return values and throw exceptions.
  • Observables represent asynchronous sets of values, providing operations usually associated with sets such as map, filter, and reduce. Observables also can be iterated over asynchronously within a coroutine.
  • Loop (event loop) is used to schedule functions, run timers, handle signals, and poll sockets for pending data or await for space to write.

Available Packages

  • Stream: Common coroutine-based interface for reading and writing data.
  • Socket: Asynchronous stream socket server and client.
  • Concurrent: Provides an easy to use interface for parallel execution with non-blocking communication and task execution.
  • DNS: Asynchronous DNS query executor, resolver and connector.
  • Filesystem: Asynchronous filesystem access.
  • HTTP: Asynchronous HTTP server and client.
  • WebSocket: Asynchronous WebSocket server and client.
  • React Adapter: Adapts the event loop and awaitables of Icicle to interfaces compatible with components built for React.

Documentation and Support

Requirements
  • PHP 5.5+ for v0.9.x branch (current stable) and v1.x branch (mirrors current stable)
  • PHP 7 for v2.0 (master) branch supporting generator delegation and return expressions
Installation

The recommended way to install Icicle is with the Composer package manager. (See the Composer installation guide for information on installing and using Composer.), (*5)

Run the following command to use Icicle in your project:, (*6)

composer require icicleio/icicle

You can also manually edit composer.json to add Icicle as a project requirement., (*7)

// composer.json
{
    "require": {
        "icicleio/icicle": "^0.9"
    }
}
Suggested
  • pcntl extension: Enables custom signal handling.
  • ev extension: Extension providing the most performant event loop implementation.
  • uv extension (PHP 7 only): Another extension providing a more performant event loop implementation (experimental).

Example

The example script below demonstrates how awaitables can be yielded in a coroutine to create interruption points. Fulfillment values of awaitables are sent to the coroutine and rejection exceptions are thrown into the coroutine., (*8)

#!/usr/bin/env php
<?php

require dirname(__DIR__) . '/vendor/autoload.php';

use Icicle\Awaitable;
use Icicle\Coroutine\Coroutine;
use Icicle\Loop;

$generator = function () {
    try {
        // Sets $start to the value returned by microtime() after approx. 1 second.
        $start = (yield Awaitable\resolve(microtime(true))->delay(1));

        echo "Sleep time: ", microtime(true) - $start, "\n";

        // Throws the exception from the rejected promise into the coroutine.
        yield Awaitable\reject(new Exception('Rejected promise'));
    } catch (Exception $e) { // Catches promise rejection reason.
        echo "Caught exception: ", $e->getMessage(), "\n";
    }

    yield Awaitable\resolve('Coroutine completed');
};

$coroutine = new Coroutine($generator());

$coroutine->done(function ($data) {
    echo $data, "\n";
});

Loop\run();

The Versions

17/03 2017

dev-master

9999999-dev http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket awaitable multitasking network coroutine interruptible

31/03 2016

v0.9.x-dev

0.9.9999999.9999999-dev http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

MIT

The Requires

  • php ^5.5|^7.0

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket awaitable multitasking network coroutine interruptible

31/03 2016

v1.x-dev

1.9999999.9999999.9999999-dev http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

MIT

The Requires

  • php ^5.5|^7.0

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket awaitable multitasking network coroutine interruptible

31/03 2016

v0.9.6

0.9.6.0 http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

MIT

The Requires

  • php ^5.5|^7.0

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket awaitable multitasking network coroutine interruptible

21/02 2016

v0.9.5

0.9.5.0 http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

MIT

The Requires

  • php ^5.5|^7.0

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket awaitable multitasking network coroutine interruptible

19/01 2016

v0.9.4

0.9.4.0 http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

MIT

The Requires

  • php ^5.5|^7.0

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket awaitable multitasking network coroutine interruptible

05/01 2016

v0.9.3

0.9.3.0 http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket awaitable multitasking network coroutine interruptible

18/12 2015

v0.9.2

0.9.2.0 http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket awaitable multitasking network coroutine interruptible

03/12 2015

v0.9.1

0.9.1.0 http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket awaitable multitasking network coroutine interruptible

02/12 2015

v0.9.0

0.9.0.0 http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket awaitable multitasking network coroutine interruptible

18/09 2015

v0.8.3

0.8.3.0 http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket multitasking network coroutine interruptible

18/09 2015

v1.0.0-beta4

1.0.0.0-beta4 http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket multitasking network coroutine interruptible

10/09 2015

v0.8.2

0.8.2.0 http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

Apache-2.0

The Requires

  • php >=5.5

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket multitasking network coroutine interruptible

10/09 2015

v1.0.0-beta3

1.0.0.0-beta3 http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

Apache-2.0

The Requires

  • php >=5.5

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket multitasking network coroutine interruptible

29/08 2015

v0.8.1

0.8.1.0 http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

Apache-2.0

The Requires

  • php >=5.5

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket multitasking network coroutine interruptible

15/08 2015

v0.8.0

0.8.0.0 http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

Apache-2.0

The Requires

  • php >=5.5

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket multitasking network coroutine interruptible

18/07 2015

v0.7.1

0.7.1.0 http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

Apache-2.0

The Requires

  • php >=5.5

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket multitasking network coroutine interruptible

18/07 2015

v1.0.0-beta2

1.0.0.0-beta2 http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

Apache-2.0

The Requires

  • php >=5.5

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket multitasking network coroutine interruptible

02/07 2015

v0.7.0

0.7.0.0 http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

Apache-2.0

The Requires

  • php >=5.5

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket multitasking network coroutine interruptible

02/07 2015

v1.0.0-beta1

1.0.0.0-beta1 http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

Apache-2.0

The Requires

  • php >=5.5

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket multitasking network coroutine interruptible

01/07 2015

v0.6.0

0.6.0.0 http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

Apache-2.0

The Requires

  • php >=5.5

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket multitasking network coroutine interruptible

20/06 2015

v0.5.3

0.5.3.0 http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

Apache-2.0

The Requires

  • php >=5.5

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket multitasking network coroutine interruptible

13/06 2015

v0.5.2

0.5.2.0 http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

Apache-2.0

The Requires

  • php >=5.5

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket multitasking network coroutine interruptible

02/06 2015

v0.5.1

0.5.1.0 http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

Apache-2.0

The Requires

  • php >=5.5

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket multitasking network coroutine interruptible

31/05 2015

v0.5.0

0.5.0.0 http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

Apache-2.0

The Requires

  • php >=5.5

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket multitasking network coroutine interruptible

21/05 2015

v0.4.1

0.4.1.0 http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

Apache-2.0

The Requires

  • php >=5.5

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket multitasking network coroutine interruptible

21/05 2015

v0.4.0

0.4.0.0 http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

Apache-2.0

The Requires

  • php >=5.5

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket multitasking network coroutine interruptible

03/05 2015

v0.3.0

0.3.0.0 http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket multitasking network coroutine interruptible

16/04 2015

v0.2.2

0.2.2.0 http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket multitasking network coroutine interruptible

02/04 2015

v0.2.1

0.2.1.0 http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket multitasking network coroutine interruptible

30/03 2015

v0.2.0

0.2.0.0 http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket multitasking network coroutine interruptible

21/03 2015

v0.1.3

0.1.3.0 http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

Apache-2.0

The Requires

  • php >=5.4

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket multitasking network coroutine interruptible

18/03 2015

v0.1.2

0.1.2.0 http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

Apache-2.0

The Requires

  • php >=5.4

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket multitasking network coroutine interruptible

13/03 2015

v0.1.1

0.1.1.0 http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

Apache-2.0

The Requires

  • php >=5.4

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket multitasking network coroutine interruptible

13/03 2015

v0.1.0

0.1.0.0 http://icicle.io

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

  Sources   Download

Apache-2.0

The Requires

  • php >=5.4

 

The Development Requires

by Aaron Piotrowski

generator server asynchronous async event promise stream socket multitasking network coroutine interruptible