Exemple #1
0
        protected Task WaitFor(NamedConnection connection, ushort messageId, CommandMessage mustBeType)
        {
            ManualResetEvent available = new ManualResetEvent(false);

            Action<MqttCommand> ready = (cmd) =>
                {
                    if (cmd.CommandMessage != mustBeType)
                    {
                        throw new ProtocolException(
                            string.Format("ERROR: Expected {0} for message ID {1} but received {2}",
                            mustBeType, messageId, cmd.CommandMessage));
                    }

                    available.Set();
                };

            return Task.Factory.StartNew(() =>
                {
                    connection.Desire(messageId, ready);
                    available.WaitOne();
                }, TaskCreationOptions.LongRunning);
        }