Asynchrnous Calls and Channels

async

(Lagarrigue, Frederic (Reigate)) #1

I assume if I want to call simultaneous async calls I need a channel per call. I was thinking of creating a pool of channels but not quite sure how and when to determine if a channel is free or not. I assume it is still needed for the callback after the initial call. Are there any examples of this kind of thing? Delphi currently, but .NET will also be needed.


(EvgenyK) #2

Delphi:
plain channels have Busy property.
I can suggest to review Phone Photo Server sample. it uses _AsyncEx interfaces.


(Lagarrigue, Frederic (Reigate)) #3

The Phone Photo Server sample still only uses a single channel. My question is if I have say 10 async calls I want to make simultaneuously, if I use the same channel for all 10 then I expect they will happen synchronously, right? If so, I need a channel per call. However, I want to be able to reuse those channels so not create one for every call. When is it safe to reuse the channel?


(EvgenyK) #4

yes, it is safe if _AsyncEx interface is used.
if _Async interface is used, you need to manually control state of channel.


(Lagarrigue, Frederic (Reigate)) #5

I realize it is safe, but what I mean is I want to be able to run processes simultaneously. I want a pool of say 10 channels, and I want to use channels when they are available. Is checking the busy flag enough? i.e Get channel from pool, if it is busy, put it back and get the next one until we have a non busy channel.


(EvgenyK) #6

yes, you need to check busy flag.
imagine case when all channels are busy. what your steps: wait for non-busy or create 10 additional channels?
if wait for non-busy, then you can just launch new requests (i.e. each new async request per channel) and it will executed only channels will be non-busy. it will work only if each request will take approximately the same time (or the same server method is executed)