PHP Classes

File: src/CallableTask.php

Recommend this page to a friend!
  Classes of Rodolfo Berrios Arce   Workflow   src/CallableTask.php   Download  
File: src/CallableTask.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Workflow
Create and run action workflows
Author: By
Last change:
Date: 1 month ago
Size: 1,097 bytes
 

Contents

Class file image Download
<?php

/*
 * This file is part of Chevere.
 *
 * (c) Rodolfo Berrios <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace
Chevere\Workflow;

use
Amp\Cancellation;
use
Amp\Parallel\Worker\Task;
use
Amp\Sync\Channel;
use
InvalidArgumentException;

/**
 * @template-implements Task<mixed, never, never>
 */
final class CallableTask implements Task
{
    private
string $callable;

   
/**
     * @var array<mixed>
     */
   
private array $arguments;

    public function
__construct(
        callable
$callable,
       
mixed ...$arguments
   
) {
        if (!
is_string($callable)) {
            throw new
InvalidArgumentException('Argument $callable must be a callable string');
        }
       
$this->callable = $callable;
       
$this->arguments = $arguments;
    }

    public function
run(Channel $channel, Cancellation $cancellation): mixed
   
{
       
// @phpstan-ignore-next-line
       
return ($this->callable)(...$this->arguments);
    }
}