예제 #1
0
        internal Chan <T> GetOrCreate <T>() where T : struct
        {
            lock (lockObj)
            {
                var type = typeof(T);
                if (chs.ContainsKey(type))
                {
                    return((Chan <T>)chs[type]);
                }

                chs[type] = new Chan <T>();
                return((Chan <T>)chs[type]);
            }
        }
예제 #2
0
        public WaitResultInstruction()
        {
            var ch = Chan <T> .Make();

            ch.Receive(
                (result, ok) =>
            {
                if (ok)
                {
                    _result = result;
                }
                _keepWaiting = false;
            }
                );
        }
예제 #3
0
        internal bool IsExists <T>(out Chan <T> ch) where T : struct
        {
            lock (lockObj)
            {
                var type = typeof(T);
                if (chs.ContainsKey(type))
                {
                    ch = (Chan <T>)chs[type];
                    return(true);
                }

                ch = null;
                return(false);
            }
        }
예제 #4
0
        public ForInstruction(Action <T> onReceive)
        {
            var ch = Chan <T> .Make();

            ch.Receive(
                (t, ok) =>
            {
                if (!ok)
                {
                    _keepWaiting = false;
                    return;
                }
                onReceive(t);
            }
                );
        }