@@ -22,32 +22,66 @@ public static function all(iterable $promises): PromiseInterface
2222 public static function make ($ workflow , ...$ arguments ): PromiseInterface
2323 {
2424 $ context = WorkflowStub::getContext ();
25+ $ result = null ;
2526
26- $ log = $ context ->storedWorkflow ->findLogByIndex ($ context ->index );
27+ while (true ) {
28+ $ log = $ context ->storedWorkflow ->findLogByIndex ($ context ->index );
29+ $ result = null ;
2730
28- if (WorkflowStub::faked ()) {
29- $ mocks = WorkflowStub::mocks ();
31+ if (WorkflowStub::faked ()) {
32+ $ mocks = WorkflowStub::mocks ();
3033
31- if (! $ log && array_key_exists ($ workflow , $ mocks )) {
32- $ result = $ mocks [$ workflow ];
34+ if (! $ log && array_key_exists ($ workflow , $ mocks )) {
35+ $ mockedResult = $ mocks [$ workflow ];
3336
34- $ log = $ context ->storedWorkflow ->createLog ([
35- 'index ' => $ context ->index ,
36- 'now ' => $ context ->now ,
37- 'class ' => $ workflow ,
38- 'result ' => Serializer::serialize (
39- is_callable ($ result ) ? $ result ($ context , ...$ arguments ) : $ result
40- ),
41- ]);
37+ $ log = $ context ->storedWorkflow ->createLog ([
38+ 'index ' => $ context ->index ,
39+ 'now ' => $ context ->now ,
40+ 'class ' => $ workflow ,
41+ 'result ' => Serializer::serialize (
42+ is_callable ($ mockedResult ) ? $ mockedResult ($ context , ...$ arguments ) : $ mockedResult
43+ ),
44+ ]);
4245
43- WorkflowStub::recordDispatched ($ workflow , $ arguments );
46+ WorkflowStub::recordDispatched ($ workflow , $ arguments );
47+ }
48+ }
49+
50+ if (! $ log ) {
51+ break ;
4452 }
53+
54+ if ($ log ->class !== Exception::class) {
55+ break ;
56+ }
57+
58+ $ result = Serializer::unserialize ($ log ->result );
59+
60+ if (! self ::isForeignExceptionResult ($ result , $ workflow )) {
61+ break ;
62+ }
63+
64+ ++$ context ->index ;
65+ WorkflowStub::setContext ($ context );
4566 }
4667
4768 if ($ log ) {
69+ $ result ??= Serializer::unserialize ($ log ->result );
70+
71+ if (
72+ WorkflowStub::isProbing ()
73+ && WorkflowStub::probeIndex () === $ context ->index
74+ && (
75+ WorkflowStub::probeClass () === null
76+ || WorkflowStub::probeClass () === $ workflow
77+ )
78+ && $ log ->class === Exception::class
79+ ) {
80+ WorkflowStub::markProbeMatched ();
81+ }
82+
4883 ++$ context ->index ;
4984 WorkflowStub::setContext ($ context );
50- $ result = Serializer::unserialize ($ log ->result );
5185 if (
5286 is_array ($ result )
5387 && array_key_exists ('class ' , $ result )
@@ -67,6 +101,13 @@ public static function make($workflow, ...$arguments): PromiseInterface
67101 return resolve ($ result );
68102 }
69103
104+ if (WorkflowStub::isProbing ()) {
105+ WorkflowStub::markProbePendingBeforeMatch ();
106+ ++$ context ->index ;
107+ WorkflowStub::setContext ($ context );
108+ return (new Deferred ())->promise ();
109+ }
110+
70111 if (! $ context ->replaying ) {
71112 $ storedChildWorkflow = $ context ->storedWorkflow ->children ()
72113 ->wherePivot ('parent_index ' , $ context ->index )
@@ -94,7 +135,14 @@ public static function make($workflow, ...$arguments): PromiseInterface
94135
95136 ++$ context ->index ;
96137 WorkflowStub::setContext ($ context );
97- $ deferred = new Deferred ();
98- return $ deferred ->promise ();
138+ return (new Deferred ())->promise ();
139+ }
140+
141+ private static function isForeignExceptionResult (mixed $ result , string $ workflow ): bool
142+ {
143+ return is_array ($ result )
144+ && isset ($ result ['sourceClass ' ])
145+ && is_string ($ result ['sourceClass ' ])
146+ && $ result ['sourceClass ' ] !== $ workflow ;
99147 }
100148}
0 commit comments