Jump to content
RaelB

Adding call to sleep blocks stage in pipeline

Recommended Posts

In the SimplePipeline project (from HL-III presentation), if I add a call to sleep in AddOne stage, the program (i.e. UI) blocks for 5 seconds.

 

procedure AddOne(const input, output: IOmniBlockingCollection);
var
  v: TOmniValue;
begin
  for v in input do
  begin
    output.Add(v.AsInteger + 1);
    Sleep(1000);
  end;
end;

I would expect this to not block the UI, since it is running in a Thread/Task?

Share this post


Link to post

SimplePipeline is, well, simple. This is the TButton event handler:

procedure TfrmSimplePipeline.btnPipelineClick(Sender: TObject);
var
  pipeline: IOmniPipeline;
  i: Integer;
  v: TOmniValue;
begin
  pipeline := Parallel.Pipeline;
  pipeline.Stage(AddOne);
  pipeline.Stage(Invert);
  pipeline.Run;

  for i := 1 to 5 do
    pipeline.Input.Add(i);
  pipeline.Input.CompleteAdding;

  for v in pipeline.Output do
    lbLog.Items.Add(Format('%.3f', [v.AsDouble]));

  pipeline := nil;
end;

As you can see, the code starts the pipeline and then runs the loop that processes the results. This loop is run in a main thread and therefore blocks the UI. If you slow down the pipeline, it needs more time to generate the results and UI is blocked.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×