Skip to content

Commit 1c755dc

Browse files
committed
Always use functions, keep When/Util for BC only
1 parent 5028b00 commit 1c755dc

6 files changed

Lines changed: 20 additions & 20 deletions

File tree

src/React/Promise/Deferred.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ public function then($fulfilledHandler = null, $errorHandler = null, $progressHa
5252
public function resolve($result = null)
5353
{
5454
if (null !== $this->completed) {
55-
return Util::promiseFor($result);
55+
return resolve($result);
5656
}
5757

58-
$this->completed = Util::promiseFor($result);
58+
$this->completed = resolve($result);
5959

6060
$this->processQueue($this->handlers, $this->completed);
6161

@@ -66,7 +66,7 @@ public function resolve($result = null)
6666

6767
public function reject($reason = null)
6868
{
69-
return $this->resolve(Util::rejectedPromiseFor($reason));
69+
return $this->resolve(reject($reason));
7070
}
7171

7272
public function progress($update = null)

src/React/Promise/FulfilledPromise.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function then($fulfilledHandler = null, $errorHandler = null, $progressHa
2222
trigger_error('Invalid $fulfilledHandler argument passed to then(), must be null or callable.', E_USER_NOTICE);
2323
}
2424

25-
return Util::promiseFor($result);
25+
return resolve($result);
2626
} catch (\Exception $exception) {
2727
return new RejectedPromise($exception);
2828
}

src/React/Promise/LazyPromise.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function then($fulfilledHandler = null, $errorHandler = null, $progressHa
1616
{
1717
if (null === $this->promise) {
1818
try {
19-
$this->promise = Util::promiseFor(call_user_func($this->factory));
19+
$this->promise = resolve(call_user_func($this->factory));
2020
} catch (\Exception $exception) {
2121
$this->promise = new RejectedPromise($exception);
2222
}

src/React/Promise/RejectedPromise.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function then($fulfilledHandler = null, $errorHandler = null, $progressHa
2222
return new RejectedPromise($this->reason);
2323
}
2424

25-
return Util::promiseFor(call_user_func($errorHandler, $this->reason));
25+
return resolve(call_user_func($errorHandler, $this->reason));
2626
} catch (\Exception $exception) {
2727
return new RejectedPromise($exception);
2828
}

src/React/Promise/Util.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,11 @@ class Util
66
{
77
public static function promiseFor($promiseOrValue)
88
{
9-
if ($promiseOrValue instanceof PromiseInterface) {
10-
return $promiseOrValue;
11-
}
12-
13-
return new FulfilledPromise($promiseOrValue);
9+
return resolve($promiseOrValue);
1410
}
1511

1612
public static function rejectedPromiseFor($promiseOrValue)
1713
{
18-
if ($promiseOrValue instanceof PromiseInterface) {
19-
return $promiseOrValue->then(function ($value) {
20-
return new RejectedPromise($value);
21-
});
22-
}
23-
24-
return new RejectedPromise($promiseOrValue);
14+
return reject($promiseOrValue);
2515
}
2616
}

src/React/Promise/functions.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,22 @@
88

99
function resolve($promiseOrValue = null)
1010
{
11-
return Util::promiseFor($promiseOrValue);
11+
if ($promiseOrValue instanceof PromiseInterface) {
12+
return $promiseOrValue;
13+
}
14+
15+
return new FulfilledPromise($promiseOrValue);
1216
}
1317

1418
function reject($promiseOrValue = null)
1519
{
16-
return Util::rejectedPromiseFor($promiseOrValue);
20+
if ($promiseOrValue instanceof PromiseInterface) {
21+
return $promiseOrValue->then(function ($value) {
22+
return new RejectedPromise($value);
23+
});
24+
}
25+
26+
return new RejectedPromise($promiseOrValue);
1727
}
1828

1929
function all($promisesOrValues)

0 commit comments

Comments
 (0)