From Asbjørn, 2 Years ago, written in Delphi (Object Pascal).
Embed
  1. procedure ChannelTest;
  2. var
  3.   chan: Channel<integer>;
  4.   producer: TThread;
  5.   consumer: TThread;
  6. begin
  7.   chan := Channel<integer>.Create();
  8.  
  9.   producer := TThread.CreateAnonymousThread(
  10.     procedure
  11.     var
  12.       data: TArray<integer>;
  13.     begin
  14.       data := [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
  15.  
  16.       chan <= data;
  17.  
  18.       chan.Close;
  19.     end
  20.   );
  21.  
  22.  
  23.   consumer := TThread.CreateAnonymousThread(
  24.     procedure
  25.     var
  26.       v: integer;
  27.     begin
  28.       while (v <= chan) do
  29.       begin
  30.         WriteLn(v);
  31.       end;
  32.     end
  33.   );
  34.  
  35.   producer.Start;
  36.   consumer.Start;
  37. end;

captcha