示例#1
0
        private IEnumerable <Expression> __concurrenthungry(CancellationToken __cancellation, Action <object> __success, Action <Exception> __failure)
        {
            Console.WriteLine(_name + " is hungry");
            var __expr3_var = new __expr3 {
                Start = (___expr) =>
                {
                    var __expr = (__expr3)___expr;
                    _left.acquire(this, __cancellation, (__res) => __expr.__op4(true, null, null), (__ex) => __expr.__op4(false, null, __ex));
                    _right.acquire(this, __cancellation, (__res) => __expr.__op4(null, true, null), (__ex) => __expr.__op4(null, false, __ex));
                }

                , End = (__expr) =>
                {
                    __enter(() => __advance(__expr.Continuator), __failure);
                }

                , __start2 = (___expr) =>
                {
                    var __expr = (__expr3)___expr;
                    __enter(() =>
                    {
                        __advance((__concurrenteat(__cancellation, (__res) =>
                        {
                            __expr.__op3(null, true, null);
                        }

                                                   , (__ex) =>
                        {
                            __expr.__op3(null, false, __ex);
                        }

                                                   )).GetEnumerator());
                    }

                            , __failure);
                }
            };

            yield return(__expr3_var);

            if (__expr3_var.Failure != null)
            {
                throw __expr3_var.Failure;
            }
            {
                __dispatch("hungry");
                if (__success != null)
                {
                    __success(null);
                }
                yield break;
            }
        }
示例#2
0
        private IEnumerable <Runtime.Expression> __concurrentC(Action <object> __success, Action <Exception> __failure)
        {
            var __expr3_var = new __expr3
            {
                Start = (___expr) =>
                {
                    var __expr = (__expr3)___expr;
                    __run(() =>
                    {
                        __listen("B", () =>
                        {
                            __expr.__op3(true, null, null);
                        }

                                 );
                        __expr.__op3(null, false, null);
                    }

                          , null, __failure);
                }

                ,
                End = (__expr) =>
                {
                    __run(() => __advance(__expr.Continuator), __success, __failure);
                }
            };

            yield return(__expr3_var);

            if (__expr3_var.Failure != null)
            {
                throw __expr3_var.Failure;
            }
            {
                if (__success != null)
                {
                    try
                    {
                        __success(null);
                    }
                    catch
                    {
                    }
                }

                yield break;
            }
        }
示例#3
0
        private IEnumerable <Expression> __concurrentmain(CancellationToken __cancellation, Action <object> __success, Action <Exception> __failure)
        {
            for (;;)
            {
                {
                    var __expr3_var = new __expr3 {
                        Start = (___expr) =>
                        {
                            var __expr = (__expr3)___expr;
                            __advance((__concurrentwork(__cancellation, (__res) =>
                            {
                                __expr.__op5(true, null, null);
                            }

                                                        , (__ex) =>
                            {
                                __expr.__op5(false, null, __ex);
                            }

                                                        )).GetEnumerator());
                            __expr.__op5(null, false, null);
                        }

                        , End = (__expr) =>
                        {
                            __enter(() => __advance(__expr.Continuator), __failure);
                        }
                    };
                    yield return(__expr3_var);

                    if (__expr3_var.Failure != null)
                    {
                        throw __expr3_var.Failure;
                    }
                }
            }

            {
                __dispatch("main");
                if (__success != null)
                {
                    __success(null);
                }
                yield break;
            }
        }
示例#4
0
        private IEnumerable <Expression> __concurrentvisit(int client, CancellationToken __cancellation, Action <object> __success, Action <Exception> __failure)
        {
            if (_chairs == 0)
            {
                Console.WriteLine($"Client {client}: the place is full!");
            }
            else
            {
                Console.WriteLine($"Client: {client}, Barber1 {barber_status(0)},  Barber2: {barber_status(1)}");
                if (_busy[0] && _busy[1])
                {
                    _chairs--;
                    {
                        var __expr2_var = new __expr2 {
                            Start = (___expr) =>
                            {
                                var __expr = (__expr2)___expr;
                                __queuevisit.Enqueue(() => __expr.__op2(true, null, null));
                                __expr.__op2(null, false, null);
                            }

                            , End = (__expr) =>
                            {
                                __enter(() => __advance(__expr.Continuator), __failure);
                            }
                        };
                        yield return(__expr2_var);

                        if (__expr2_var.Failure != null)
                        {
                            throw __expr2_var.Failure;
                        }
                    }

                    _chairs++;
                }

                for (int i = 0; i < 2; i++)
                {
                    if (!_busy[i])
                    {
                        {
                            var __expr3_var = new __expr3 {
                                Start = (___expr) =>
                                {
                                    var __expr = (__expr3)___expr;
                                    __advance((__concurrentshave_client(client, i, __cancellation, (__res) =>
                                    {
                                        __expr.__op3(true, null, null);
                                    }

                                                                        , (__ex) =>
                                    {
                                        __expr.__op3(false, null, __ex);
                                    }

                                                                        )).GetEnumerator());
                                    __expr.__op3(null, false, null);
                                }

                                , End = (__expr) =>
                                {
                                    __enter(() => __advance(__expr.Continuator), __failure);
                                }
                            };
                            yield return(__expr3_var);

                            if (__expr3_var.Failure != null)
                            {
                                throw __expr3_var.Failure;
                            }
                        }

                        break;
                    }
                }

                if (__queuevisit.Any())
                {
                    __queuevisit.Dequeue()();
                }
            }

            _clients--;
            if (_clients == 0)
            {
                App.Stop();
            }

            {
                __dispatch("visit");
                if (__success != null)
                {
                    __success(null);
                }
                yield break;
            }
        }
示例#5
0
        private IEnumerable <Expression> __concurrentmain(CancellationToken __cancellation, Action <object> __success, Action <Exception> __failure)
        {
            var meetings = 0;

            if (Arguments.Length != 1 || !int.TryParse(Arguments[0], out meetings))
            {
                meetings = 600;
            }

            var firstRunColors  = new[] { Color.blue, Color.red, Color.yellow };
            var secondRunColors = new[] { Color.blue, Color.red, Color.yellow, Color.red, Color.yellow, Color.blue, Color.red, Color.yellow, Color.red, Color.blue };
            //run and await
            IEnumerable <Chameneo> firstRun, secondRun;
            var __expr3_var = new __expr3 {
                Start = (___expr) =>
                {
                    var __expr = (__expr3)___expr;
                    __advance((__concurrentRun(meetings, firstRunColors, __cancellation, (__res) =>
                    {
                        __expr.firstRun = (System.Collections.Generic.IEnumerable <ChameneoRedux.Chameneo>)__res;
                        __expr.__op3(true, null, null);
                    }

                                               , (__ex) =>
                    {
                        __expr.__op3(false, null, __ex);
                    }

                                               )).GetEnumerator());
                    __advance((__concurrentRun(meetings, secondRunColors, __cancellation, (__res) =>
                    {
                        __expr.secondRun = (System.Collections.Generic.IEnumerable <ChameneoRedux.Chameneo>)__res;
                        __expr.__op3(null, true, null);
                    }

                                               , (__ex) =>
                    {
                        __expr.__op3(null, false, __ex);
                    }

                                               )).GetEnumerator());
                }

                , End = (__expr) =>
                {
                    __enter(() => __advance(__expr.Continuator), __failure);
                }
            };

            yield return(__expr3_var);

            if (__expr3_var.Failure != null)
            {
                throw __expr3_var.Failure;
            }
            firstRun  = __expr3_var.firstRun;
            secondRun = __expr3_var.secondRun;
            //print results
            PrintColors();
            Console.WriteLine();
            PrintRun(firstRunColors, firstRun);
            Console.WriteLine();
            PrintRun(secondRunColors, secondRun);
            App.Stop();
            {
                __dispatch("main");
                if (__success != null)
                {
                    __success(null);
                }
                yield break;
            }
        }