FlowR.Core/ApplicationResponses.cs
/// <summary>
///     [internal use] Send and wait for a response
/// </summary>
/// <param name="app"></param>
/// <param name="message"></param>
/// <param name="timeoutSeconds"></param>
/// <returns></returns>
[internal use] Send and wait for a response
[ internal use ] Send and wait for a response
public async Task<string> WaitResponse(Application app, IMessageResponse message, int timeoutSeconds = 2)
        {
            _pending.TryAdd(message.GetUuid(), message);
            await app.Communication.SendMessage(message);
            var answerCancel = new CancellationTokenSource();
            answerCancel.CancelAfter(TimeSpan.FromSeconds(timeoutSeconds));
            return await Task.Run(() =>
            {
                var response = "";
                while (!_completed.TryGetValue(message.GetUuid(), out response))
                {
                    Task.Delay(2, answerCancel.Token);
                }
                return response;
            }, answerCancel.Token);
        }
public async Task < string > WaitResponse ( Application app , IMessageResponse message , int timeoutSeconds = 2 ) { _pending . TryAdd ( message . GetUuid ( ) , message ) ; await app . Communication . SendMessage ( message ) ; var answerCancel = new CancellationTokenSource ( ) ; answerCancel . CancelAfter ( TimeSpan . FromSeconds ( timeoutSeconds ) ) ; return await Task . Run ( ( ) => { var response = " " ; while ( ! _completed . TryGetValue ( message . GetUuid ( ) , out response ) ) { Task . Delay ( 2 , answerCancel . Token ) ; } return response ; } , answerCancel . Token ) ; }
[internal use] Send and wait for a response
[ internal use ] Send and wait for a response
// remove completed //_completed.TryRemove(message.GetUuid(), out _); // @todo if hit the timeout _completed remain an extra item, how to remove it // bad solution but give the idea, a pruning routine which remove completed, but who knows if they are already used? a flag ?
None
app
Application
None
message
IMessageResponse
None
timeoutSeconds
int
None