Example #1
0
        public AsyncReply <string> Stream(int count)
        {
            var   reply      = new AsyncReply <string>();
            var   msg        = new object[] { "Have you throught what if a function has multiple returns ?", "So you can return chunks of IO operation that not yet finished.", "Also, what about the progress ?", "This is an example of both.", "Use it anyway you like" };
            Timer timer      = null;
            var   msgCounter = 0;

            timer = new Timer((x) =>
            {
                reply.TriggerProgress(AsyncReply.ProgressType.Execution, count, 22);

                if (count % 2 == 0 && msgCounter < msg.Length)
                {
                    reply.TriggerChunk(msg[msgCounter++]);
                }

                count--;
                if (count <= 0)
                {
                    timer.Dispose();
                    reply.Trigger("Done");
                }
            }, null, 10, 3000);

            return(reply);
        }