{"id":15022112,"url":"https://github.com/logicalsteps/async","last_synced_at":"2025-04-12T06:13:03.645Z","repository":{"id":57015514,"uuid":"150279866","full_name":"logicalsteps/async","owner":"logicalsteps","description":"async await implementation using generators in php","archived":false,"fork":false,"pushed_at":"2020-08-28T09:00:34.000Z","size":116,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-12T06:12:57.327Z","etag":null,"topics":["amphp","async","async-await","asynchronous","await","callback","composer","concurrency","coroutine","event","event-loop","generator","guzzle","httplug","non-blocking","php7","promise","reactphp"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/logicalsteps.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-25T14:34:31.000Z","updated_at":"2025-03-02T14:30:29.000Z","dependencies_parsed_at":"2022-08-22T09:31:41.918Z","dependency_job_id":null,"html_url":"https://github.com/logicalsteps/async","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logicalsteps%2Fasync","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logicalsteps%2Fasync/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logicalsteps%2Fasync/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logicalsteps%2Fasync/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/logicalsteps","download_url":"https://codeload.github.com/logicalsteps/async/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248525138,"owners_count":21118619,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["amphp","async","async-await","asynchronous","await","callback","composer","concurrency","coroutine","event","event-loop","generator","guzzle","httplug","non-blocking","php7","promise","reactphp"],"created_at":"2024-09-24T19:57:28.432Z","updated_at":"2025-04-12T06:13:03.619Z","avatar_url":"https://github.com/logicalsteps.png","language":"PHP","readme":"# Async \u0026 Await for PHP\n\n[![Build Status](https://travis-ci.org/logicalsteps/async.svg?branch=master)](https://travis-ci.org/logicalsteps/async)\n[![Code Coverage](https://scrutinizer-ci.com/g/logicalsteps/async/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/logicalsteps/async/?branch=master)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/logicalsteps/async/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/logicalsteps/async/?branch=master)\n[![Latest Stable Version](https://poser.pugx.org/logicalsteps/async/v/stable.svg)](https://packagist.org/packages/logicalsteps/async)\n[![Total Downloads](https://poser.pugx.org/logicalsteps/async/downloads.svg)](https://packagist.org/packages/logicalsteps/async)\n[![License](https://poser.pugx.org/logicalsteps/async/license.svg)](https://packagist.org/packages/logicalsteps/async)\n\nSimplify your asynchronous code and make it readable like synchronous code. It works similar to Async and await in other \nlanguages such as JavaScript and C#\n\nIt can be used standalone with callback functions. It also works with the promise interface of the following frameworks\n - [ReactPHP](https://github.com/reactphp/promise)\n - [Amp](https://amphp.org/amp/promises/)\n - [Guzzle](https://github.com/guzzle/promises)\n - [Httplug](https://github.com/php-http/promise)\n \n\nIt can do cooperative multitasking with the event loop interfaces of the following frameworks\n - [ReactPHP](https://github.com/reactphp/event-loop)\n - [Amp](https://amphp.org/amp/event-loop/)\n\n## Installation\n\nAsync can be installed with [Composer](http://getcomposer.org)\nby adding it as a dependency to your project's composer.json file. It can be done using the following command.\n\n```bash\ncomposer require logicalsteps/async\n```\n\nPlease refer to [Composer's documentation](https://github.com/composer/composer/blob/master/doc/00-intro.md#introduction)\nfor more detailed installation and usage instructions.\n\n## Usage\n\nConsider the following example\n \n```php\n\u003c?php\nrequire __DIR__ . '/../vendor/autoload.php';\nuse Web3\\Web3; //installed with `composer require sc0vu/web3.php` on the commandline\n\nfunction balance($accountNumber)\n{\n    $web3 = new Web3('http://localhost:8545');\n    $eth = $web3-\u003eeth;\n    $eth-\u003eaccounts(function ($error, $result) use ($eth, $accountNumber) {\n        if ($error) {\n            return;\n        }\n        $accounts = $result;\n        $eth-\u003egetBalance($accounts[$accountNumber], function ($error, $result) {\n            if ($error) {\n                return;\n            }\n            var_export((int)$result-\u003evalue);\n        });\n    });\n}\n\nbalance(0);\n```\n\nIf it is all synchronous, our function will simply be\n\n```php\nfunction balance($accountNumber)\n{\n    $web3 = new Web3('http://localhost:8545');\n    $eth = $web3-\u003eeth;\n    $accounts = $eth-\u003eaccounts();\n    $balance = $eth-\u003egetBalance($accounts[$accountNumber]);\n    return (int)$balance-\u003evalue;\n}\n\nvar_export(balance(0));\n\n```\n\nWith Async library it can be written as the following\n\n```php\nuse LogicalSteps\\Async\\Async;\nuse Web3\\Web3;\n\nfunction balance($accountNumber)\n{\n\n    $web3 = new Web3('http://localhost:8545');\n    $eth = $web3-\u003eeth;\n    $accounts = yield [$eth, 'accounts'];\n    $balance = yield [$eth, 'getBalance', $accounts[$accountNumber]];\n    $value = (int)$balance-\u003evalue;\n    return $value;\n}\n\nAsync::await(balance(0))-\u003ethen('var_export');\n```\n\nNow the code is clean and looks synchronous, but runs asynchronously for better performance getting us \nbest of both worlds :) \n\nFor more examples and integration with the frameworks take a look at [examples folder](examples)","funding_links":[],"categories":["Alternative libraries"],"sub_categories":["Tunnel"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flogicalsteps%2Fasync","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flogicalsteps%2Fasync","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flogicalsteps%2Fasync/lists"}