1
0
mirror of https://github.com/danog/amp.git synced 2024-12-12 09:29:45 +01:00
amp/examples/iterators/emitter-gc.php

33 lines
668 B
PHP
Raw Normal View History

#!/usr/bin/env php
<?php
require __DIR__ . '/../../vendor/autoload.php';
use Amp\Emitter;
use Amp\Loop;
Loop::run(function () {
$emitter = new Emitter;
Loop::defer(function () use ($emitter) {
try {
yield $emitter->emit(1);
print "Emit done.\n";
yield $emitter->emit(2);
print "Never reached...\n";
$emitter->complete();
} finally {
print "Garbage collected...\n";
}
});
$iterator = $emitter->iterate();
yield $iterator->advance();
yield new Amp\Delayed(0);
unset($emitter, $iterator);
2018-01-08 22:00:15 +01:00
\gc_collect_cycles();
print "Done.\n";
});