53 parent::__construct(
$type, $key );
54 foreach ( [
'doWork',
'doCachedWork',
'fallback',
'error' ] as $name ) {
55 if ( isset( $callbacks[$name] ) ) {
56 if ( !is_callable( $callbacks[$name] ) ) {
57 throw new MWException(
"Invalid callback provided for '$name' function." );
59 $this->$name = $callbacks[$name];
62 if ( !isset( $this->
doWork ) ) {
63 throw new MWException(
"No callback provided for 'doWork' function." );
65 $this->cacheable = isset( $this->doCachedWork );
69 return ( $this->
doWork )();
73 if ( $this->doCachedWork ) {
74 return ( $this->doCachedWork )();
86 public function error( $status ) {
88 return ( $this->
error )( $status );
Convenience class for dealing with PoolCounters using callbacks.
fallback()
A work not so good (eg.
__construct( $type, $key, array $callbacks)
Build a PoolCounterWork class from a type, key, and callback map.
error( $status)
Do something with the error, like showing it to the user.
getCachedWork()
Retrieve the work from cache.
callable null $doCachedWork
doWork()
Actually perform the work, caching it if needed.
Class for dealing with PoolCounters using class members.