From 75a59f10a3d0a8f64b210fae5624542782b28356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Sat, 26 Jun 2021 13:36:36 +0200 Subject: [PATCH 1/2] Improve documentation regarding deprecated Factory --- README.md | 68 +++++++++++++++++++++++++++---------------------- src/Factory.php | 14 +++++++--- 2 files changed, 49 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index b5559f6c..fd33d20c 100644 --- a/README.md +++ b/README.md @@ -13,31 +13,31 @@ single [`run()`](#run) call that is controlled by the user. * [Quickstart example](#quickstart-example) * [Usage](#usage) - * [Loop](#loop) - * [Loop methods](#loop-methods) - * [get()](#get) - * [Factory](#factory) - * [create()](#create) - * [Loop implementations](#loop-implementations) - * [StreamSelectLoop](#streamselectloop) - * [ExtEventLoop](#exteventloop) - * [ExtLibeventLoop](#extlibeventloop) - * [ExtLibevLoop](#extlibevloop) - * [ExtEvLoop](#extevloop) - * [ExtUvLoop](#extuvloop) - * [LoopInterface](#loopinterface) - * [run()](#run) - * [stop()](#stop) - * [addTimer()](#addtimer) - * [addPeriodicTimer()](#addperiodictimer) - * [cancelTimer()](#canceltimer) - * [futureTick()](#futuretick) - * [addSignal()](#addsignal) - * [removeSignal()](#removesignal) - * [addReadStream()](#addreadstream) - * [addWriteStream()](#addwritestream) - * [removeReadStream()](#removereadstream) - * [removeWriteStream()](#removewritestream) + * [Loop](#loop) + * [Loop methods](#loop-methods) + * [get()](#get) + * [~~Factory~~](#factory) + * [~~create()~~](#create) + * [Loop implementations](#loop-implementations) + * [StreamSelectLoop](#streamselectloop) + * [ExtEventLoop](#exteventloop) + * [ExtLibeventLoop](#extlibeventloop) + * [ExtLibevLoop](#extlibevloop) + * [ExtEvLoop](#extevloop) + * [ExtUvLoop](#extuvloop) + * [LoopInterface](#loopinterface) + * [run()](#run) + * [stop()](#stop) + * [addTimer()](#addtimer) + * [addPeriodicTimer()](#addperiodictimer) + * [cancelTimer()](#canceltimer) + * [futureTick()](#futuretick) + * [addSignal()](#addsignal) + * [removeSignal()](#removesignal) + * [addReadStream()](#addreadstream) + * [addWriteStream()](#addwritestream) + * [removeReadStream()](#removereadstream) + * [removeWriteStream()](#removewritestream) * [Install](#install) * [Tests](#tests) * [License](#license) @@ -262,18 +262,26 @@ Loop::run(); See [`LoopInterface`](#loopinterface) for more details about available methods. -### Factory +### ~~Factory~~ -The `Factory` class exists as a convenient way to pick the best available +> Deprecated since v1.2.0, see [`Loop` class](#loop) instead. + +The deprecated `Factory` class exists as a convenient way to pick the best available [event loop implementation](#loop-implementations). -#### create() +#### ~~create()~~ + +> Deprecated since v1.2.0, see [`Loop::get()`](#get) instead. -The `create(): LoopInterface` method can be used to create a new event loop -instance: +The deprecated `create(): LoopInterface` method can be used to +create a new event loop instance: ```php +// deprecated $loop = React\EventLoop\Factory::create(); + +// new +$loop = React\EventLoop\Loop::get(); ``` This method always returns an instance implementing [`LoopInterface`](#loopinterface), diff --git a/src/Factory.php b/src/Factory.php index 1843d86e..30bbfd7c 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -3,15 +3,22 @@ namespace React\EventLoop; /** - * The `Factory` class exists as a convenient way to pick the best available event loop implementation. + * [Deprecated] The `Factory` class exists as a convenient way to pick the best available event loop implementation. + * + * @deprecated 1.2.0 See Loop instead. + * @see Loop */ final class Factory { /** - * Creates a new event loop instance + * [Deprecated] Creates a new event loop instance * * ```php + * // deprecated * $loop = React\EventLoop\Factory::create(); + * + * // new + * $loop = React\EventLoop\Loop::get(); * ``` * * This method always returns an instance implementing `LoopInterface`, @@ -19,7 +26,8 @@ final class Factory * * This method should usually only be called once at the beginning of the program. * - * @deprecated Use Loop::get instead + * @deprecated 1.2.0 See Loop::get() instead. + * @see Loop::get() * * @return LoopInterface */ From 86b5f82e743bc34a55c0c3497e038461072609a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Wed, 30 Jun 2021 13:12:33 +0200 Subject: [PATCH 2/2] Update usage examples --- README.md | 14 ++++++++++---- examples/02-periodic.php | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index fd33d20c..ef5c5ce6 100644 --- a/README.md +++ b/README.md @@ -48,8 +48,12 @@ single [`run()`](#run) call that is controlled by the user. Here is an async HTTP server built with just the event loop. ```php +addPeriodicTimer(0.1, function () { - echo "Tick" . PHP_EOL; + echo 'Tick' . PHP_EOL; }); + $loop->addTimer(1.0, function () use ($loop, $timer) { $loop->cancelTimer($timer); echo 'Done' . PHP_EOL; @@ -163,7 +169,7 @@ like this: use React\EventLoop\Loop; $timer = Loop::addPeriodicTimer(0.1, function () { - echo 'tick!' . PHP_EOL; + echo 'Tick' . PHP_EOL; }); Loop::addTimer(1.0, function () use ($timer) { diff --git a/examples/02-periodic.php b/examples/02-periodic.php index 0604f846..4413870d 100644 --- a/examples/02-periodic.php +++ b/examples/02-periodic.php @@ -5,7 +5,7 @@ require __DIR__ . '/../vendor/autoload.php'; $timer = Loop::addPeriodicTimer(0.1, function () { - echo 'tick!' . PHP_EOL; + echo 'Tick' . PHP_EOL; }); Loop::addTimer(1.0, function () use ($timer) { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy