lazhen
2025-01-09 8afe90b633046db39042aada36b88193062f8cff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
Quintiq file version 2.0
#parent: #root
MethodOverride Operation (LibOpt_Task task) as stream[JSON]
{
  TextBody:
  [*
    result := stream[JSON]::Success();
    
    if( task.CanContinue() )
    {
      context := task.TaskContext().astype( LibOpt_TaskContextIterator );
      if( isnull( context ) )
      {
        context := task.TaskContext( relnew, LibOpt_TaskContextIterator );
      }
      
      stopcriterion := this.StopCriterion();
      
      result := stream[JSON]::Success();
      count := this.MaxParallel() - context.NrOfSubtasks();
      for( i := count; i > 0
                       and stopcriterion.CanStartIteration( task ) 
                       and not stopcriterion.ShouldStop( task ); i-- )
      {
        reactive_calls := LibOpt_CurrentTransaction::GetSpawnedReactiveCalls();
        time := OS::PrecisionCounter();
        continue := this.Continue( task );
        if( this.ForceInOneTransaction() or this.Run().InOneTransaction() or reactive_calls = LibOpt_CurrentTransaction::GetSpawnedReactiveCalls() )
        {
          i++;
          context.NrOfIterations( context.NrOfIterations() + 1 );
          
          if( reactive_calls <> LibOpt_CurrentTransaction::GetSpawnedReactiveCalls() )
          {
            LibOpt_SnapshotWarning::Throw( task,
                                           Translations::LibOpt_Iterator_NotInOneTransaction( this.Name(), LibOpt_CurrentTransaction::GetSpawnedReactiveCallNames( time ) ),
                                           Translations::LibOpt_Iterator_NotInOneTransaction_Solution(),
                                           LibOpt_Issue::Severity_4_High()
                                         );
          }
        }
        else
        {
          finish := continue->|
                    this->Repeat( task, context );
          result := result->Merge( continue, finish );
          context.NrOfSubtasks( context.NrOfSubtasks() + 1 );
        }
      }
    }
    
    return result;
  *]
}