Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Remove LazyPromise #98

Merged
merged 1 commit into from
Aug 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Table of Contents
* [Promise](#promise-2)
* [FulfilledPromise](#fulfilledpromise)
* [RejectedPromise](#rejectedpromise)
* [LazyPromise](#lazypromise)
* [Functions](#functions)
* [resolve()](#resolve)
* [reject()](#reject)
Expand Down Expand Up @@ -156,7 +155,6 @@ Neither its state nor its result (or error) can be modified.
* [Promise](#promise-2)
* [FulfilledPromise](#fulfilledpromise)
* [RejectedPromise](#rejectedpromise)
* [LazyPromise](#lazypromise)

#### PromiseInterface::then()

Expand Down Expand Up @@ -361,27 +359,6 @@ $promise = React\Promise\RejectedPromise($reason);
Note, that `$reason` **cannot** be a promise. It's recommended to use
[reject()](#reject) for creating rejected promises.

### LazyPromise

Creates a promise which will be lazily initialized by `$factory` once a consumer
calls the `then()` method.

```php
$factory = function () {
$deferred = new React\Promise\Deferred();

// Do some heavy stuff here and resolve the deferred once completed

return $deferred->promise();
};

$promise = new React\Promise\LazyPromise($factory);

// $factory will only be executed once we call then()
$promise->then(function ($value) {
});
```

### Functions

Useful functions for creating, joining, mapping and reducing collections of
Expand Down
61 changes: 0 additions & 61 deletions src/LazyPromise.php

This file was deleted.

13 changes: 1 addition & 12 deletions src/Promise.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,8 @@ private function settle(PromiseInterface $result)

private function unwrap($promise)
{
$promise = $this->extract($promise);

while ($promise instanceof self && null !== $promise->result) {
$promise = $this->extract($promise->result);
}

return $promise;
}

private function extract($promise)
{
if ($promise instanceof LazyPromise) {
$promise = $promise->promise();
$promise = $promise->result;
}

if ($promise === $this) {
Expand Down
96 changes: 0 additions & 96 deletions tests/LazyPromiseTest.php

This file was deleted.