lazhen
2025-01-07 b3987122cbbc46c5c59d3173f37fca3170b6dc5a
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
Quintiq file version 2.0
#parent: #root
MethodOverride Operation (LibOpt_Task task) as stream[JSON]
{
  TextBody:
  [*
    start_init := OS::PrecisionCounter();
    
    stream_json := null( stream[JSON] );
    
    this.HasRetrievedAlgorithmFromStore( false );
    program := this.DoConstructAlgorithm();
    this.AlgorithmStoreWriteProgram( &program );
    
    if( this.InOneTransaction() )
    {
      this.DoInitialize( task, program );
      
      LibOpt_AlgorithmStopwatch::Add( program, LibOpt_SnapshotAlgorithm::FrameworkInitialize(), LibOpt_Utility::TimeSince( start_init ) );
      
      stream_json := this.DoExecute( program, task );
    }
    else
    {
      init_stream := this.DoInitializeReactive( task, program ); 
      // Correctly calculate the init time, without blocking the dataset
      stream_json := init_stream->AsVoid()->() { // Note: this is several times faster than 'init_stream->( unused_object ) {'
        // We have to use a reactive code block here to ensure that LibOpt_Utility::TimeSince( start_init ) is called after init_stream.
        LibOpt_AlgorithmStopwatch::Add( program, LibOpt_SnapshotAlgorithm::FrameworkInitialize(), LibOpt_Utility::TimeSince( start_init ) );
      }->|this->DoExecuteReactive( program, task );
    }
    
    return stream_json;
  *]
}