Skip to content

Commit 1a58b6a

Browse files
author
Jeremiah VALERIE
committed
Removed all eventLoop references
1 parent d0b351d commit 1a58b6a

File tree

3 files changed

+11
-43
lines changed

3 files changed

+11
-43
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,4 @@ install: composer update --prefer-dist --no-interaction
2929
script: if [ "$TRAVIS_PHP_VERSION" == "5.6" ]; then phpunit -d xdebug.max_nesting_level=1000 --debug --coverage-clover build/logs/clover.xml; else phpunit --debug; fi
3030

3131
after_success:
32-
- composer require "satooshi/php-coveralls:^1.0"
33-
- travis_retry php vendor/bin/coveralls -v
32+
- if [[ "$TRAVIS_PHP_VERSION" != "5.6"]]; then composer require "satooshi/php-coveralls:^1.0" && travis_retry php vendor/bin/coveralls -v; fi

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ data sources such as databases or web services via batching and caching.
1111

1212
## Requirements
1313

14-
* This library require [React/Promise](https://github.com/reactphp/promise) and PHP >= 5.5 to works.
15-
* The [React/EventLoop](https://github.com/reactphp/event-loop) component are **totally optional** (see `await` method for more details).
14+
This library require [React/Promise](https://github.com/reactphp/promise) and PHP >= 5.5 to works.
1615

1716
## Getting Started
1817

@@ -40,8 +39,8 @@ A batch loading callable / callback accepts an Array of keys, and returns a Prom
4039
resolves to an Array of values.
4140

4241
Then load individual values from the loader. DataLoaderPHP will coalesce all
43-
individual loads which occur within a single frame of execution (a single tick
44-
of the event loop if install or using `await` method) and then call your batch function with all requested keys.
42+
individual loads which occur within a single frame of execution (using `await` method)
43+
and then call your batch function with all requested keys.
4544

4645
```php
4746
$userLoader->load(1)

src/DataLoader.php

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,15 @@ class DataLoader
3535
*/
3636
private $queue = [];
3737

38-
/**
39-
* @var null|\React\EventLoop\LoopInterface
40-
*/
41-
private $eventLoop;
42-
43-
/**
44-
* @var Promise
45-
*/
46-
private $resolvedPromise;
47-
4838
/**
4939
* @var self[]
5040
*/
5141
private static $instances = [];
5242

53-
public function __construct(BatchLoadFn $batchLoadFn, Option $options = null)
43+
public function __construct(callable $batchLoadFn, Option $options = null)
5444
{
5545
$this->batchLoadFn = $batchLoadFn;
5646
$this->options = $options ?: new Option();
57-
$this->eventLoop = class_exists('React\\EventLoop\\Factory') ? \React\EventLoop\Factory::create() : null;
5847
$this->promiseCache = $this->options->getCacheMap();
5948
self::$instances[] = $this;
6049
}
@@ -97,12 +86,7 @@ function ($resolve, $reject) use (&$promise, $key, $shouldBatch) {
9786
// A single dispatch should be scheduled per queue at the time when the
9887
// queue changes from "empty" to "full".
9988
if (count($this->queue) === 1) {
100-
if ($shouldBatch) {
101-
// If batching, schedule a task to dispatch the queue.
102-
$this->enqueuePostPromiseJob(function () {
103-
$this->dispatchQueue();
104-
});
105-
} else {
89+
if (!$shouldBatch) {
10690
// Otherwise dispatch the (queue of one) immediately.
10791
$this->dispatchQueue();
10892
}
@@ -124,11 +108,11 @@ function (callable $resolve, callable $reject) {
124108
/**
125109
* Loads multiple keys, promising an array of values:
126110
*
127-
* [$a, $b] = $myLoader->loadMany(['a', 'b']);
111+
* list($a, $b) = $myLoader->loadMany(['a', 'b']);
128112
*
129113
* This is equivalent to the more verbose:
130114
*
131-
* [$a, $b] = \React\Promise\all([
115+
* list($a, $b) = \React\Promise\all([
132116
* $myLoader->load('a'),
133117
* $myLoader->load('b')
134118
* ]);
@@ -207,7 +191,9 @@ public function __destruct()
207191
if ($this->needProcess()) {
208192
foreach ($this->queue as $data) {
209193
try {
210-
$data['promise']->cancel();
194+
/** @var Promise $promise */
195+
$promise = $data['promise'];
196+
$promise->cancel();
211197
} catch (\Exception $e) {
212198
// no need to do nothing if cancel failed
213199
}
@@ -310,22 +296,6 @@ private function checkKey($key, $method)
310296
}
311297
}
312298

313-
/**
314-
* @param $fn
315-
*/
316-
private function enqueuePostPromiseJob($fn)
317-
{
318-
if (!$this->resolvedPromise) {
319-
$this->resolvedPromise = \React\Promise\resolve();
320-
}
321-
322-
if ($this->eventLoop) {
323-
$this->resolvedPromise->then(function () use ($fn) {
324-
$this->eventLoop->nextTick($fn);
325-
});
326-
}
327-
}
328-
329299
/**
330300
* Given the current state of a Loader instance, perform a batch load
331301
* from its current queue.

0 commit comments

Comments
 (0)