mirror of
https://gitee.com/mix-php/mix.git
synced 2024-12-02 03:37:56 +08:00
feat:examples: Add CoroutineRun
This commit is contained in:
parent
dbcc4156fe
commit
a1b7a17234
26
examples/api-skeleton/src/Command/CoroutineRun.php
Normal file
26
examples/api-skeleton/src/Command/CoroutineRun.php
Normal 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();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
26
examples/cli-skeleton/src/Command/CoroutineRun.php
Normal file
26
examples/cli-skeleton/src/Command/CoroutineRun.php
Normal 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();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
26
examples/grpc-skeleton/src/Command/CoroutineRun.php
Normal file
26
examples/grpc-skeleton/src/Command/CoroutineRun.php
Normal 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();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
26
examples/web-skeleton/src/Command/CoroutineRun.php
Normal file
26
examples/web-skeleton/src/Command/CoroutineRun.php
Normal 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();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
26
examples/websocket-skeleton/src/Command/CoroutineRun.php
Normal file
26
examples/websocket-skeleton/src/Command/CoroutineRun.php
Normal 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();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user