<?php

/**
 * TEST: Awaitables chaining test.
 */

declare(strict_types=1);
use Tester\Assert;
require(__DIR__ . '/../bootstrap.php');

$loop = React\EventLoop\Factory::create();

$timer = new Awaited\Timer($loop, -.250, true, null, true);
$semaphore = new Awaited\Semaphore;

$count = 0;

$awaitables = new Awaited\Awaitables($timer, $semaphore);
$awaitables->each(function(callable $complete) use(&$count): void {
	$complete();
	$count++;
});

$loop->addTimer(1.0, function() use($loop): void {
	$loop->stop();
});

$loop->run();

Assert::same(4, $count);

Assert::exception(function(): void {
	new Awaited\Awaitables;
}, InvalidArgumentException::class);