@@ -974,85 +974,44 @@ public static function uuid7(?DateTimeInterface $dateTime = null): PromiseInterf
974974 }
975975
976976 /**
977- * Get a mutex by name or create a new one .
977+ * Create a new mutex .
978978 *
979979 * If a mutex is yielded without calling `lock()`, the Workflow will continue
980980 * only when the lock is released.
981981 *
982982 * ```php
983- * yield Workflow::mutex('my-mutex');
984- * ```
983+ * $this->>mutex = Workflow::mutex();
985984 *
986- * Now to continue only when the lock is acquired:
985+ * // Continue only when the lock is released
986+ * yield $this->mutex;
987987 *
988- * ```php
988+ * // Continue only when the lock is acquired
989989 * yield Workflow::mutex('my-mutex')->lock();
990990 * ```
991991 *
992- * Note: in this case, if the lock is already acquired, the Workflow will be blocked until it's released
993- *
994- * @param non-empty-string $name The name of the mutex.
995- */
996- public static function mutex (string $ name ): MutexInterface
997- {
998- /** @var WorkflowContextInterface $context */
999- $ context = self ::getCurrentContext ();
1000-
1001- return $ context ->mutex ($ name );
1002- }
1003-
1004- /**
1005- * Create a conditional mutex that is locked when any of the conditions are met.
1006- *
1007- * @param non-empty-string $name
1008- *
1009- * Example:
1010- *
1011- * Monitor when the number of threads exceeds 10:
1012- *
1013- * ```php
1014- * #[WorkflowMethod]
1015- * function start() {
1016- * // Register a conditional mutex that will be locked when the number of threads exceeds 10
1017- * Workflow::conditionalMutex(
1018- * 'limit',
1019- * fn() => count($this->threads) > 10,
1020- * );
1021- * // ...
1022- * }
1023- *
1024- * #[SignalMethod]
1025- * function addTask(Task $task) {
1026- * yield Workflow::runLocked('limit', function() {
1027- * $key = array_key_last($this->threads) + 1;
1028- * yield $this->threads[$key] = Workflow::executeChildWorkflow(...);
1029- * unset($this->threads[$key]);
1030- * });
1031- * }
1032- * ```
992+ * Note: in the last case, if the lock is already acquired, the Workflow will be blocked until it's released.
1033993 */
1034- public function conditionalMutex ( string $ name , PromiseInterface | callable ... $ lockConditions ): MutexInterface
994+ public static function mutex ( ): MutexInterface
1035995 {
1036996 /** @var WorkflowContextInterface $context */
1037997 $ context = self ::getCurrentContext ();
1038998
1039- return $ context ->conditionalMutex ( $ name , ... $ lockConditions );
999+ return $ context ->mutex ( );
10401000 }
10411001
10421002 /**
10431003 * Run a function when the mutex is released.
1044- * The mutex is locked for the duration of the function if it's not a conditional mutex.
1045- * Conditional mutexes are locked only when all conditions are met.
1004+ * The mutex is locked for the duration of the function.
10461005 *
1047- * @see Workflow::conditionalMutex()
1006+ * @param non-empty-string|MutexInterface $mutex Mutex name or instance.
1007+ *@see Workflow::conditionalMutex()
10481008 *
1049- * @param non-empty-string|MutexInterface $name Mutex name or instance.
10501009 */
1051- public function runLocked (string |MutexInterface $ name , callable $ callable ): PromiseInterface
1010+ public function runLocked (string |MutexInterface $ mutex , callable $ callable ): PromiseInterface
10521011 {
10531012 /** @var WorkflowContextInterface $context */
10541013 $ context = self ::getCurrentContext ();
10551014
1056- return $ context ->runLocked ($ name , $ callable );
1015+ return $ context ->runLocked ($ mutex , $ callable );
10571016 }
10581017}
0 commit comments