{"id":17437159,"url":"https://github.com/thavarshan/matrix","last_synced_at":"2025-04-09T15:06:46.049Z","repository":{"id":257804725,"uuid":"864636852","full_name":"Thavarshan/matrix","owner":"Thavarshan","description":"⚛︎ Bringing JavaScript-style async to PHP! Manage asynchronous tasks with ease using a modern, fiber-powered API for seamless concurrency and error handling.","archived":false,"fork":false,"pushed_at":"2025-01-27T17:10:02.000Z","size":343,"stargazers_count":40,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-09T15:06:40.517Z","etag":null,"topics":["async","fiber","javascript","matrix","non-blocking","php","task"],"latest_commit_sha":null,"homepage":"","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/Thavarshan.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":".github/SUPPORT.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"thavarshan","buy_me_a_coffee":"thavarshan"}},"created_at":"2024-09-28T18:44:00.000Z","updated_at":"2025-03-30T08:12:15.000Z","dependencies_parsed_at":"2024-12-06T05:22:19.922Z","dependency_job_id":"4b1e8684-25f7-4b46-9597-19fcd52c31c6","html_url":"https://github.com/Thavarshan/matrix","commit_stats":{"total_commits":16,"total_committers":2,"mean_commits":8.0,"dds":0.125,"last_synced_commit":"6df42468e198883ff9d98846ca1f556b3bcd2ecc"},"previous_names":["thavarshan/matrix"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thavarshan%2Fmatrix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thavarshan%2Fmatrix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thavarshan%2Fmatrix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thavarshan%2Fmatrix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Thavarshan","download_url":"https://codeload.github.com/Thavarshan/matrix/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248055284,"owners_count":21040157,"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":["async","fiber","javascript","matrix","non-blocking","php","task"],"created_at":"2024-10-17T11:06:13.754Z","updated_at":"2025-04-09T15:06:46.010Z","avatar_url":"https://github.com/Thavarshan.png","language":"PHP","funding_links":["https://github.com/sponsors/thavarshan","https://buymeacoffee.com/thavarshan"],"categories":[],"sub_categories":[],"readme":"[![Matrix](./assets/Banner.jpg)](https://github.com/Thavarshan/matrix)\n\n# Matrix\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/jerome/matrix.svg)](https://packagist.org/packages/jerome/matrix)\n[![Tests](https://github.com/Thavarshan/matrix/actions/workflows/run-tests.yml/badge.svg?label=tests\u0026branch=main)](https://github.com/Thavarshan/matrix/actions/workflows/run-tests.yml)\n[![Check \u0026 Fix Styling](https://github.com/Thavarshan/matrix/actions/workflows/laravel-pint.yml/badge.svg)](https://github.com/Thavarshan/matrix/actions/workflows/laravel-pint.yml)\n[![Total Downloads](https://img.shields.io/packagist/dt/jerome/matrix.svg)](https://packagist.org/packages/jerome/matrix)\n\nMatrix is a PHP library that brings asynchronous, non-blocking functionality to PHP, inspired by JavaScript's `async`/`await` syntax. With Matrix, you can handle asynchronous tasks and manage concurrency using promises and a simple, intuitive API.\n\n## Why Choose Matrix?\n\nMatrix simplifies asynchronous programming in PHP by combining promises with ReactPHP's event loop. It supports non-blocking execution, seamless error handling, and easy integration with existing projects.\n\n### Key Features\n\n- **JavaScript-like API**: Use `async()` and `await()` for straightforward asynchronous programming.\n- **Powered by ReactPHP**: Ensures non-blocking execution using ReactPHP's event loop.\n- **Robust Error Handling**: Catch and handle exceptions with `.catch()` or `try-catch`.\n- **Automatic Loop Management**: The event loop runs automatically to handle promise resolution.\n\n## Installation\n\nInstall Matrix via Composer:\n\n```bash\ncomposer require jerome/matrix\n```\n\nEnsure the following extension is enabled:\n\n- `sockets`\n\nReactPHP promises and the event loop will be installed automatically via Composer.\n\n## API Overview\n\n### `async(callable $callable): PromiseInterface`\n\nWraps a callable into an asynchronous function that returns a promise.\n\n#### Example:\n\n```php\nuse function async;\n\n$func = async(fn () =\u003e 'Success');\n\n$func-\u003ethen(fn ($value) =\u003e echo $value) // Outputs: Success\n    -\u003ecatch(fn ($e) =\u003e echo 'Error: ' . $e-\u003egetMessage());\n```\n\n### `await(PromiseInterface $promise): mixed`\n\nAwaits the resolution of a promise and returns its value.\n\n#### Example:\n\n```php\nuse function await;\n\ntry {\n    $result = await(async(fn () =\u003e 'Success'));\n    echo $result; // Outputs: Success\n} catch (\\Throwable $e) {\n    echo 'Error: ' . $e-\u003egetMessage();\n}\n```\n\n## Examples\n\n### Running Asynchronous Tasks\n\n```php\n$promise = async(fn () =\u003e 'Task Completed');\n\n$promise-\u003ethen(fn ($value) =\u003e echo $value) // Outputs: Task Completed\n    -\u003ecatch(fn ($e) =\u003e echo 'Error: ' . $e-\u003egetMessage());\n```\n\n### Using the Await Syntax\n\n```php\ntry {\n    $result = await(async(fn () =\u003e 'Finished Task'));\n    echo $result; // Outputs: Finished Task\n} catch (\\Throwable $e) {\n    echo 'Error: ' . $e-\u003egetMessage();\n}\n```\n\n### Handling Errors\n\n```php\n$promise = async(fn () =\u003e throw new \\RuntimeException('Task Failed'));\n\n$promise-\u003ethen(fn ($value) =\u003e echo $value)\n    -\u003ecatch(fn ($e) =\u003e echo 'Caught Error: ' . $e-\u003egetMessage()); // Outputs: Caught Error: Task Failed\n```\n\n## How It Works\n\n1. **Event Loop Management**: The `async()` function ensures the event loop runs until the promise is resolved or rejected.\n2. **Promise Interface**: Promises provide `then` and `catch` methods for handling success and errors.\n3. **Synchronous Await**: The `await()` function allows synchronous-style code to resolve promises.\n\n## Testing\n\nRun the test suite to ensure everything is working as expected:\n\n```bash\ncomposer test\n```\n\n## Contributing\n\nWe welcome contributions! To get started, fork the repository and create a pull request with your changes.\n\n## License\n\nMatrix is open-source software licensed under the MIT License.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthavarshan%2Fmatrix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthavarshan%2Fmatrix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthavarshan%2Fmatrix/lists"}