<?php
namespace GuzzleHttp\Event;
/**
 *
 * @package JCHAT::FRAMEWORK::administrator::components::com_jchat
 * @subpackage framework
 * @subpackage guzzlehttp
 * @subpackage guzzle
 * @subpackage Event
 * @author Joomla! Extensions Store
 * @copyright (C) 2015 - Joomla! Extensions Store
 * @license GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html
 */
defined ( '_JEXEC' ) or die ( 'Restricted access' );
/**
 * Abstract request event that can be retried.
 */
class AbstractRetryableEvent extends AbstractTransferEvent
{
    /**
     * Mark the request as needing a retry and stop event propagation.
     *
     * This action allows you to retry a request without emitting the "end"
     * event multiple times for a given request. When retried, the request
     * emits a before event and is then sent again using the client that sent
     * the original request.
     *
     * When retrying, it is important to limit the number of retries you allow
     * to prevent infinite loops.
     *
     * This action can only be taken during the "complete" and "error" events.
     *
     * @param int $afterDelay If specified, the amount of time in milliseconds
     *                        to delay before retrying. Note that this must
     *                        be supported by the underlying RingPHP handler
     *                        to work properly. Set to 0 or provide no value
     *                        to retry immediately.
     */
    public function retry($afterDelay = 0)
    {
        // Setting the transition state to 'retry' will cause the next state
        // transition of the transaction to retry the request.
        $this->transaction->state = 'retry';

        if ($afterDelay) {
            $this->transaction->request->getConfig()->set('delay', $afterDelay);
        }

        $this->stopPropagation();
    }
}
