-
-
Save mbonneau/1461a357bed1151a46c70a9a545f5b79 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Interop\Async\Promise; | |
use Rx\Observable; | |
function toLazyPromise(Observable $observable) { | |
return new class($observable) implements Promise { | |
/** @var Promise */ | |
private $promise; | |
private $sourceObservable; | |
public function __construct(Observable $sourceObservable) | |
{ | |
$this->sourceObservable = $sourceObservable; | |
} | |
public function when(callable $onResolved) | |
{ | |
if (!$this->promise) { | |
$this->promise = $this->sourceObservable->toPromise(); | |
} | |
return $this->promise->when($onResolved); | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment