Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
297 additions
and
297 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Amp; | ||
|
||
use Interop\Async\Loop; | ||
|
||
final class Emanator implements Emitter { | ||
use CallableMaker, Internal\Producer; | ||
|
||
/** | ||
* @param callable(callable(mixed $value): Promise $emit): \Generator $emitter | ||
* | ||
* @throws \TypeError Thrown if the callable does not return a Generator. | ||
*/ | ||
public function __construct(callable $emitter) { | ||
$result = $emitter($this->callableFromInstanceMethod("emit")); | ||
|
||
if (!$result instanceof \Generator) { | ||
throw new \TypeError("The callable did not return a Generator"); | ||
} | ||
|
||
Loop::defer(function () use ($result) { | ||
$coroutine = new Coroutine($result); | ||
$coroutine->when(function ($exception, $value) { | ||
if ($this->resolved) { | ||
return; | ||
} | ||
|
||
if ($exception) { | ||
$this->fail($exception); | ||
return; | ||
} | ||
|
||
$this->resolve($value); | ||
}); | ||
}); | ||
} | ||
} |
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
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
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
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
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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.