I am using OTL for the first time and I was trying to use the Async/Await abstraction.
Now, I created a small program just to see what will happen. It's just a button and it calls this procedure.
procedure TForm2.Button1Click(Sender: TObject);
var i : integer;
begin
Button1.enabled := false; //Only for second try
for i := 0 to 100 do
begin
Async(
procedure begin
sleep(5000);
end).
Await(
procedure begin
//First Try - Button1.Enabled := true;
//Second Try - showmessage('finished')
end
);
Button1.enabled := true; //Only for the second try.
end;
end;
First Try
For this it works fine the first time, disable the button, sleep for the asyncs and then enable it back.
But the second time I click the button, it is disabled but never gets enabled again.
Second Try
This time I wanted to show a message x100 times and it works the first time aswell, but when I call the procedure again I get the following error TOminCommunicationEndpoint.Send: Queue is full
Can someone who has used this library explain to me, why am I getting this error? And if it is related to the problem with the first try?
It seems you are hitting an internal limitation of OTL.
Each call to Async-Await starts a new thread and returns immediately. When the loop is done you end up with 100 threads, each waiting 5 seconds before executing the Await code.
AFAIK, there is a limitation of 60 concurrent threads in OTL when using the threadpool.