Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
asmblah committed Oct 27, 2023
0 parents commit 958e29b
Show file tree
Hide file tree
Showing 16 changed files with 2,745 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: CI

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
php-version: [8.1, 8.2]

steps:
# Check out the repository under $GITHUB_WORKSPACE, so this job can access it.
- uses: actions/checkout@v2

- name: Use PHP ${{ matrix.php-version }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}

phpstan:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Use PHP 8.2
uses: shivammathur/setup-php@v2
with:
php-version: 8.2

- name: Install Composer dependencies
run: composer install

- name: Run PHPStan
run: vendor/bin/phpstan analyse -c phpstan.neon.dist
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.DS_Store
._.DS_Store
/.idea
/.phpunit.cache
/.phpunit.result.cache
/var
/vendor
21 changes: 21 additions & 0 deletions MIT-LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Copyright 2023 Dan Phillimore (asmblah)
https://github.com/nytris/tasque-event-loop/

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Tasque EventLoop.

[![Build Status](https://github.com/nytris/tasque-event-loop/workflows/CI/badge.svg)](https://github.com/nytris/tasque-event-loop/actions?query=workflow%3ACI)

Run a [ReactPHP][2] [event loop][3] within a conventional PHP application using [Tasque][1].

## Why?
To allow periodic background tasks, such as sending keep-alive or heartbeat messages,
to be performed in a traditional PHP environment where there would otherwise be no event loop.

## Usage
Install this package with Composer:

```shell
$ composer install tasque/event-loop
```

Configure Nytris platform:

`nytris.config.php`

```php
<?php

declare(strict_types=1);

use Nytris\Boot\BootConfig;
use Nytris\Boot\PlatformConfig;
use Tasque\Tasque;

$bootConfig = new BootConfig(new PlatformConfig(__DIR__ . '/var/cache/nytris/'));

$bootConfig->installPackage(Tasque::class);
$bootConfig->installPackage(TasqueEventLoop::class);

return $bootConfig;
```

### Setting a timer

Just use a standard ReactPHP timer, as long as the package is configured in `nytris.config.php` as above.

`index.php`

```php
<?php

declare(strict_types=1);

use React\EventLoop\Loop;

require_once __DIR__ . '/vendor/autoload.php';

Loop::addPeriodicTimer(1, function () {
print 'Timer elapsed' . PHP_EOL;
});
```

## See also
- [Tasque][1]
- [ReactPHP][2]
- [ReactPHP EventLoop][3]

[1]: https://github.com/nytris/tasque
[2]: https://reactphp.org/
[3]: https://github.com/reactphp/event-loop
33 changes: 33 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "tasque/event-loop",
"type": "project",
"license": "MIT",
"autoload": {
"psr-4": {
"Tasque\\EventLoop\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tasque\\EventLoop\\Tests\\": "tests/"
}
},
"require": {
"php": ">=8.1",
"react/event-loop": "1.x-dev",
"tasque/tasque": "dev-main"
},
"require-dev": {
"mockery/mockery": "^1.6",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-mockery": "^1.1",
"phpunit/phpunit": "^10.2"
},
"config": {
"platform": {
"php": "8.1"
},
"sort-packages": true
},
"minimum-stability": "dev"
}

0 comments on commit 958e29b

Please sign in to comment.