Skip to content

An object reference sticks in the library #394

@bileslav

Description

@bileslav

The code below works as I would expect: it completes. But if I replace the bar with baz on line 42, the program no longer completes, because in this case a reference to the Foo remains somewhere inside the library. This doesn't seem to be the expected behavior.

<?php
declare (strict_types = 1);

use Revolt\EventLoop;

require 'vendor/autoload.php';

final class Foo
{
	private readonly string $id;

	public function __construct()
	{
		/** @var \Closure */
		$f = Amp\weakClosure(function (): void {
			echo "...\n";
		});

		$this->id = EventLoop::repeat(1, $f);
	}

	public function __destruct()
	{
		EventLoop::cancel($this->id);
	}

	public function bar(): string
	{
		return 'OK';
	}

	public function baz(): never
	{
		throw new Exception();
	}
}

(function (): void {
	$foo = new Foo();

	var_dump(Amp\Future\awaitAll([
		Amp\async($foo->bar(...)),
	]));
})();

EventLoop::run();

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions