public function submit(Context $context, $work, int $priority = 0): Promise
    {
        $job = new class($context) extends Placeholder {

            public $priority;

            public $generator;
        };
        
        $job->priority = $priority;
        $job->generator = ($work instanceof \Generator) ? $work : Coroutine::generate($work, $context);
        
        for ($inserted = null, $count = \count($this->jobs), $i = 0; $i < $count; $i++) {
            if ($priority <= $this->jobs[$i]->priority) {
                $inserted = \array_splice($this->jobs, $i, 0, [
                    $job
                ]);
                
                break;
            }
        }
        
        if ($inserted === null) {
            $this->jobs[] = $job;
        }
        
        if ($this->running < $this->concurrency) {
            $this->running++;
            
            $context->getLoop()->defer(\Closure::fromCallable([
                $this,
                'executeNextJob'
            ]));
        }
        
        return $context->keepBusy($job->promise());
    }
public function submit(Context $context, $work, int $priority = 0): Promise
    {
        $job = new class($context) extends Placeholder {

            public $priority;

            public $generator;
        };
        
        $job->priority = $priority;
        $job->generator = ($work instanceof \Generator) ? $work : Coroutine::generate($work, $context);
        
        for ($inserted = null, $count = \count($this->jobs), $i = 0; $i < $count; $i++) {
            if ($priority <= $this->jobs[$i]->priority) {
                $inserted = \array_splice($this->jobs, $i, 0, [
                    $job
                ]);
                
                break;
            }
        }
        
        if ($inserted === null) {
            $this->jobs[] = $job;
        }
        
        if ($this->running < $this->concurrency) {
            $this->running++;
            
            $context->getLoop()->defer(\Closure::fromCallable([
                $this,
                'executeNextJob'
            ]));
        }
        
        return $context->keepBusy($job->promise());
    }
public function submit ( Context $ context , $ work , int $ priority = 0 ) : Promise { $ job = new class ( $ context ) extends Placeholder { public $ priority ; public $ generator ; } ; $ job -> priority = $ priority ; $ job -> generator = ( $ work instanceof \ Generator ) ? $ work : Coroutine :: generate ( $ work , $ context ) ; for ( $ inserted = null , $ count = \ count ( $ this -> jobs ) , $ i = 0 ; $ i < $ count ; $ i ++ ) { if ( $ priority <= $ this -> jobs [ $ i ] -> priority ) { $ inserted = \ array_splice ( $ this -> jobs , $ i , 0 , [ $ job ] ) ; break ; } } if ( $ inserted === null ) { $ this -> jobs [ ] = $ job ; } if ( $ this -> running < $ this -> concurrency ) { $ this -> running ++ ; $ context -> getLoop ( ) -> defer ( \ Closure :: fromCallable ( [ $ this , 'executeNextJob' ] ) ) ; } return $ context -> keepBusy ( $ job -> promise ( ) ) ; }
Submit a job to the executor.

Jobs are callbacks that return a result value, a promise or are generators that will be run as coroutine.

@param mixed $work Callback or Generator object.
@param int $priority
@return mixed Result of the job callback.

@throws \Throwable Error thrown by the job.
Submit a job to the executor .