1
0
mirror of https://github.com/danog/parallel.git synced 2024-12-14 01:57:25 +01:00
parallel/src/ContextInterface.php

63 lines
1.3 KiB
PHP
Raw Normal View History

<?php
namespace Icicle\Concurrent;
/**
* Interface for all types of execution contexts.
*/
2015-07-10 23:07:52 +02:00
interface ContextInterface
{
/**
* Checks if the context is running.
*
* @return bool True if the context is running, otherwise false.
*/
public function isRunning();
/**
* Acquires a lock on the context.
*/
public function lock();
/**
* Unlocks the context.
*/
public function unlock();
/**
2015-07-10 23:07:52 +02:00
* Invokes a function while maintaining a lock for the calling context.
*
* @param callable $callback The function to invoke.
*
* @return mixed The value returned by the callback.
*/
public function synchronized(callable $callback);
/**
* Starts the context execution.
*/
public function start();
/**
* Stops context execution.
*/
public function stop();
/**
* Immediately kills the context without invoking any handlers.
*/
public function kill();
/**
* Gets a promise that resolves when the context ends and joins with the
* parent context.
*
* @return PromiseInterface Promise that is resolved when the context finishes.
*/
public function join();
/**
* Executes the context's main code.
*/
public function run();
}