2015-07-09 08:35:34 +02:00
|
|
|
<?php
|
|
|
|
namespace Icicle\Concurrent;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Interface for all types of execution contexts.
|
|
|
|
*/
|
|
|
|
interface Context
|
|
|
|
{
|
|
|
|
/**
|
2015-07-09 20:13:20 +02:00
|
|
|
* Checks if the context is running.
|
2015-07-09 08:35:34 +02:00
|
|
|
*
|
2015-07-09 20:13:20 +02:00
|
|
|
* @return bool True if the context is running, otherwise false.
|
|
|
|
*/
|
|
|
|
public function isRunning();
|
|
|
|
|
|
|
|
/**
|
2015-07-10 09:22:04 +02:00
|
|
|
* Acquires a lock on the context.
|
2015-07-09 20:13:20 +02:00
|
|
|
*/
|
|
|
|
public function lock();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unlocks the context.
|
|
|
|
*/
|
|
|
|
public function unlock();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Executes a callback with write access to the context data.
|
|
|
|
*/
|
2015-07-10 09:22:04 +02:00
|
|
|
public function synchronized(callable $callback);
|
2015-07-09 20:13:20 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Starts the context execution.
|
|
|
|
*/
|
|
|
|
public function start();
|
|
|
|
|
|
|
|
/**
|
2015-07-10 09:22:04 +02:00
|
|
|
* 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.
|
2015-07-09 20:13:20 +02:00
|
|
|
*/
|
|
|
|
public function join();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Executes the context's main code.
|
2015-07-09 08:35:34 +02:00
|
|
|
*/
|
2015-07-09 20:13:20 +02:00
|
|
|
public function run();
|
2015-07-09 08:35:34 +02:00
|
|
|
}
|