Page MenuHomeWickedGov Phorge

CriticalSectionScope.php
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

CriticalSectionScope.php

<?php
namespace Wikimedia\RequestTimeout;
/**
* Class for automatically ending a critical section when a variable goes out
* of scope.
*/
class CriticalSectionScope {
/** @var int */
private $id;
/** @var callable */
private $exitCallback;
/** @var callable|null */
private $implicitExitCallback;
/** @var bool */
private $hasExited = false;
/**
* @internal
* @param int $id
* @param callable $exitCallback
* @param callable|null $implicitExitCallback
*/
public function __construct( $id, $exitCallback, $implicitExitCallback ) {
$this->id = $id;
$this->exitCallback = $exitCallback;
$this->implicitExitCallback = $implicitExitCallback;
}
/**
* If the section has not already been exited, exit it and call the
* destruct callback.
*
* @throws TimeoutException
*/
public function __destruct() {
if ( !$this->hasExited ) {
$this->exit();
if ( $this->implicitExitCallback ) {
( $this->implicitExitCallback )( $this->id );
}
}
}
/**
* Exit the critical section
*
* @throws TimeoutException
*/
public function exit() {
if ( !$this->hasExited ) {
$this->hasExited = true;
( $this->exitCallback )( $this->id );
}
}
/**
* Get an integer uniquely identifying the section (within the scope of the
* parent RequestTimeout object).
*
* @since 1.1.0
* @return int
*/
public function getId() {
return $this->id;
}
}

File Metadata

Mime Type
text/x-php
Expires
Wed, Aug 19, 13:22 (3 w, 3 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
c4/df/45b423181ab8f2a617a8bb7957ec
Default Alt Text
CriticalSectionScope.php (1 KB)

Event Timeline