File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ --- 
2+ sidebar_position : 12 
3+ --- 
4+ 
5+ # Continue As New  
6+ 
7+ Laravel Workflow supports the ** Continue As New**  pattern, allowing a running workflow to restart itself with new arguments.
8+ This is useful when you need to:
9+ 
10+ *  Prevent unbounded workflow history growth.
11+ *  Model iterative loops or recursive workflows.
12+ *  Split long-running workflows into smaller, manageable executions while preserving continuity.
13+ 
14+ ## Using ` continueAsNew `   
15+ 
16+ To restart a workflow as new, call the static method ` WorkflowStub::continueAsNew(...) `  from within the workflow’s ` execute() `  method.
17+ 
18+ ``` php 
19+ use Workflow\ActivityStub;
20+ use Workflow\Workflow;
21+ use Workflow\WorkflowStub;
22+ 
23+ class CounterWorkflow extends Workflow
24+ {
25+     public function execute(int $count = 0, int $max = 3)
26+     {
27+         $result = yield ActivityStub::make(CountActivity::class, $count);
28+ 
29+         if ($count >= $max) {
30+             return 'workflow_' . $result;
31+         }
32+ 
33+         return yield WorkflowStub::continueAsNew($count + 1, $max);
34+     }
35+ }
36+ ``` 
37+ 
38+ In this example:
39+ 
40+ *  The workflow executes an activity each iteration.
41+ *  If the maximum count has not been reached, it continues as new with incremented arguments.
42+ *  The final result is returned only when the loop completes.
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments