feat:examples: Add CoroutineRun

This commit is contained in:
liujian 2022-05-01 17:14:05 +08:00
parent dbcc4156fe
commit a1b7a17234
5 changed files with 130 additions and 0 deletions

View File

@ -0,0 +1,26 @@
<?php
namespace App\Command;
use Mix\Cli\RunInterface;
use Mix\Init\StaticInit;
use App\Container\DB;
use App\Container\RDS;
class CoroutineRun implements RunInterface
{
public function main(): void
{
$func = function () {
// do something
};
\Swoole\Coroutine\run(function () use ($func) {
StaticInit::finder(__DIR__ . '/../../src/Container')->exec('init');
DB::enableCoroutine();
RDS::enableCoroutine();
$func();
});
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace App\Command;
use Mix\Cli\RunInterface;
use Mix\Init\StaticInit;
use App\Container\DB;
use App\Container\RDS;
class CoroutineRun implements RunInterface
{
public function main(): void
{
$func = function () {
// do something
};
\Swoole\Coroutine\run(function () use ($func) {
StaticInit::finder(__DIR__ . '/../../src/Container')->exec('init');
DB::enableCoroutine();
RDS::enableCoroutine();
$func();
});
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace App\Command;
use Mix\Cli\RunInterface;
use Mix\Init\StaticInit;
use App\Container\DB;
use App\Container\RDS;
class CoroutineRun implements RunInterface
{
public function main(): void
{
$func = function () {
// do something
};
\Swoole\Coroutine\run(function () use ($func) {
StaticInit::finder(__DIR__ . '/../../src/Container')->exec('init');
DB::enableCoroutine();
RDS::enableCoroutine();
$func();
});
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace App\Command;
use Mix\Cli\RunInterface;
use Mix\Init\StaticInit;
use App\Container\DB;
use App\Container\RDS;
class CoroutineRun implements RunInterface
{
public function main(): void
{
$func = function () {
// do something
};
\Swoole\Coroutine\run(function () use ($func) {
StaticInit::finder(__DIR__ . '/../../src/Container')->exec('init');
DB::enableCoroutine();
RDS::enableCoroutine();
$func();
});
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace App\Command;
use Mix\Cli\RunInterface;
use Mix\Init\StaticInit;
use App\Container\DB;
use App\Container\RDS;
class CoroutineRun implements RunInterface
{
public function main(): void
{
$func = function () {
// do something
};
\Swoole\Coroutine\run(function () use ($func) {
StaticInit::finder(__DIR__ . '/../../src/Container')->exec('init');
DB::enableCoroutine();
RDS::enableCoroutine();
$func();
});
}
}