public function stop()
{
$state = $this->getState();
if ($state === Runtime::STATE_CREATED || $state === Runtime::STATE_DESTROYED) {
return Promise::doReject(new RejectionException("It is not possible to stop runtime from state [{$state}]."));
} else {
if ($state === Runtime::STATE_STOPPED) {
return Promise::doResolve('Runtime has been already stopped.');
}
}
$this->setState(Runtime::STATE_STOPPED);
$emitter = $this->getEventEmitter();
$emitter->emit('beforeStop');
$emitter->emit('stop');
$emitter->emit('afterStop');
return Promise::doResolve('Runtime has been stopped.');
}