jenkins-bot has submitted this change and it was merged.

Change subject: Added ScopedCallback functions for early execution or 
cancellation.
......................................................................


Added ScopedCallback functions for early execution or cancellation.

Change-Id: I6493cfa81d778c47aa7283dc3196989384235f0a
---
M includes/ScopedCallback.php
1 file changed, 30 insertions(+), 1 deletion(-)

Approvals:
  Parent5446: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/ScopedCallback.php b/includes/ScopedCallback.php
index 1d5b26b..8ecd874 100644
--- a/includes/ScopedCallback.php
+++ b/includes/ScopedCallback.php
@@ -22,6 +22,8 @@
 
 /**
  * Class for asserting that a callback happens when an dummy object leaves 
scope
+ *
+ * @since 1.21
  */
 class ScopedCallback {
        /** @var Closure */
@@ -34,7 +36,34 @@
                $this->callback = $callback;
        }
 
+       /**
+        * Trigger a scoped callback and destroy it.
+        * This is the same is just setting it to null.
+        *
+        * @param ScopedCallback $sc
+        */
+       public static function consume( ScopedCallback &$sc = null ) {
+               $sc = null;
+       }
+
+       /**
+        * Destroy a scoped callback without triggering it
+        *
+        * @param ScopedCallback $sc
+        */
+       public static function cancel( ScopedCallback &$sc = null ) {
+               if ( $sc ) {
+                       $sc->callback = null;
+               }
+               $sc = null;
+       }
+
+       /**
+        * Trigger the callback when this leaves scope
+        */
        function __destruct() {
-               call_user_func( $this->callback );
+               if ( $this->callback !== null ) {
+                       call_user_func( $this->callback );
+               }
        }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/53799
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I6493cfa81d778c47aa7283dc3196989384235f0a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Parent5446 <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to