Skip to content

Commit

Permalink
Change to use new Nytris package API
Browse files Browse the repository at this point in the history
  • Loading branch information
asmblah committed Oct 30, 2023
1 parent 958e29b commit 51c8844
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 113 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ declare(strict_types=1);

use Nytris\Boot\BootConfig;
use Nytris\Boot\PlatformConfig;
use Tasque\Tasque;
use Tasque\EventLoop\TasqueEventLoopPackage;
use Tasque\TasquePackage;

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

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

return $bootConfig;
```
Expand Down
192 changes: 96 additions & 96 deletions composer.lock

Large diffs are not rendered by default.

14 changes: 6 additions & 8 deletions src/TasqueEventLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@

namespace Tasque\EventLoop;

use Asmblah\PhpCodeShift\Shifter\Filter\FileFilter;
use Composer\InstalledVersions;
use Nytris\Core\Package\PackageConfigInterface;
use Nytris\Core\Package\PackageContextInterface;
use Nytris\Core\Package\PackageInterface;
use React\EventLoop\Loop;
use Tasque\Tasque;

Expand Down Expand Up @@ -49,14 +48,11 @@ public static function getVendor(): string
/**
* @inheritDoc
*/
public static function install(PackageConfigInterface $packageConfig): void
public static function install(PackageContextInterface $packageContext, PackageInterface $package): void
{
self::$installed = true;

$tasque = new Tasque();

$reactEventLoopInstallPath = realpath(InstalledVersions::getInstallPath('react/event-loop'));
$tasque->excludeFiles(new FileFilter($reactEventLoopInstallPath . '/**'));
Tasque::excludeComposerPackage('react/event-loop');

/*
* Install a ReactPHP EventLoop future tick handler that invokes the Tasque tock hook.
Expand Down Expand Up @@ -86,6 +82,8 @@ public static function install(PackageConfigInterface $packageConfig): void

Loop::futureTick($tickTock);

$tasque = new Tasque();

// Run the ReactPHP event loop itself inside a Tasque green thread.
$eventLoopThread = $tasque->createThread(function () {
Loop::run();
Expand Down
4 changes: 2 additions & 2 deletions src/TasqueEventLoopInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Tasque\EventLoop;

use Nytris\Core\Package\PackageInterface;
use Nytris\Core\Package\PackageFacadeInterface;

/**
* Interface TasqueEventLoopInterface.
Expand All @@ -22,6 +22,6 @@
*
* @author Dan Phillimore <dan@ovms.co>
*/
interface TasqueEventLoopInterface extends PackageInterface
interface TasqueEventLoopInterface extends PackageFacadeInterface
{
}
32 changes: 32 additions & 0 deletions src/TasqueEventLoopPackage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* Tasque EventLoop - ReactPHP event loop using a Tasque green thread.
* Copyright (c) Dan Phillimore (asmblah)
* https://github.com/nytris/tasque-event-loop/
*
* Released under the MIT license.
* https://github.com/nytris/tasque-event-loop/raw/main/MIT-LICENSE.txt
*/

declare(strict_types=1);

namespace Tasque\EventLoop;

/**
* Class TasqueEventLoopPackage.
*
* Configures the installation of Tasque EventLoop.
*
* @author Dan Phillimore <dan@ovms.co>
*/
class TasqueEventLoopPackage implements TasqueEventLoopPackageInterface
{
/**
* @inheritDoc
*/
public function getPackageFacadeFqcn(): string
{
return TasqueEventLoop::class;
}
}
27 changes: 27 additions & 0 deletions src/TasqueEventLoopPackageInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/*
* Tasque EventLoop - ReactPHP event loop using a Tasque green thread.
* Copyright (c) Dan Phillimore (asmblah)
* https://github.com/nytris/tasque-event-loop/
*
* Released under the MIT license.
* https://github.com/nytris/tasque-event-loop/raw/main/MIT-LICENSE.txt
*/

declare(strict_types=1);

namespace Tasque\EventLoop;

use Nytris\Core\Package\PackageInterface;

/**
* Interface TasqueEventLoopPackageInterface.
*
* Configures the installation of Tasque EventLoop.
*
* @author Dan Phillimore <dan@ovms.co>
*/
interface TasqueEventLoopPackageInterface extends PackageInterface
{
}
14 changes: 10 additions & 4 deletions tests/Functional/WithOtherBackgroundThreadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@

namespace Tasque\EventLoop\Tests\Functional;

use Nytris\Core\Package\PackageConfigInterface;
use Nytris\Core\Package\PackageContextInterface;
use Tasque\Core\Scheduler\ContextSwitch\NTockStrategy;
use Tasque\EventLoop\TasqueEventLoop;
use Tasque\EventLoop\TasqueEventLoopPackageInterface;
use Tasque\EventLoop\Tests\AbstractTestCase;
use Tasque\EventLoop\Tests\Functional\Harness\Log;
use Tasque\EventLoop\Tests\Functional\Harness\WithOtherBackgroundThread\MainThread;
use Tasque\Tasque;
use Tasque\TasquePackageInterface;

/**
* Class WithOtherBackgroundThreadTest.
Expand All @@ -39,9 +41,13 @@ class WithOtherBackgroundThreadTest extends AbstractTestCase

public function setUp(): void
{
Tasque::setSchedulerStrategy(new NTockStrategy(1));
Tasque::install(mock(PackageConfigInterface::class));
TasqueEventLoop::install(mock(PackageConfigInterface::class));
Tasque::install(mock(PackageContextInterface::class), mock(TasquePackageInterface::class, [
'getSchedulerStrategy' => new NTockStrategy(1),
]));
TasqueEventLoop::install(
mock(PackageContextInterface::class),
mock(TasqueEventLoopPackageInterface::class)
);

$this->log = new Log();
$this->tasque = new Tasque();
Expand Down

0 comments on commit 51c8844

Please sign in to comment.