<?php

declare (strict_types=1);
namespace GDAVSCOPE\Amp\Parallel\Context;

use GDAVSCOPE\Amp\Cancellation;
use GDAVSCOPE\Amp\ForbidCloning;
use GDAVSCOPE\Amp\ForbidSerialization;
use GDAVSCOPE\Amp\Parallel\Ipc\IpcHub;
use GDAVSCOPE\Amp\Parallel\Ipc\LocalIpcHub;
final class ThreadContextFactory implements ContextFactory
{
    use ForbidCloning;
    use ForbidSerialization;
    /**
     * @param positive-int $childConnectTimeout Number of seconds the child will attempt to connect to the parent
     *      before failing.
     * @param IpcHub $ipcHub Optional IpcHub instance.
     */
    public function __construct(private readonly int $childConnectTimeout = 5, private readonly IpcHub $ipcHub = new LocalIpcHub())
    {
    }
    public function start(array|string $script, ?Cancellation $cancellation = null): ThreadContext
    {
        return ThreadContext::start($this->ipcHub, $script, $cancellation, $this->childConnectTimeout);
    }
}
