コード例 #1
0
        public ResultAwatier Back()
        {
            if (senders.Count == 0)
            {
                var GhostThread = Fiber.Current;

                if (GhostThread == null)
                {
                    GhostThread = this;
                }

                var waitingGhostThread = new ResultAwatier(GhostThread);

                receivers.Enqueue(waitingGhostThread);
            }


            if (senders.TryDequeue(out ResultAwatier sender))
            {
                sender.IsCompleted = true;

                var previousSyncContext = SynchronizationContext.Current;
                SynchronizationContext.SetSynchronizationContext(_SynchronizationContext);
                sender.Continuation?.Invoke();
                SynchronizationContext.SetSynchronizationContext(previousSyncContext);


                return(sender);
            }
            else
            {
                return(null);
            }
        }
コード例 #2
0
        public ResultAwatier Read()
        {
            if (senders.Count == 0)
            {
                var GhostThread = Fiber.Current;

                if (GhostThread == null)
                {
                    GhostThread = this;
                }

                var waitingGhostThread = new ResultAwatier(GhostThread);

                receivers.Enqueue(waitingGhostThread);
                return(waitingGhostThread);
            }

            if (senders.TryPeek(out ResultAwatier sender))
            {
                sender.IsCompleted = true;
                return(sender);
            }
            else
            {
                return(null);
            }
        }
コード例 #3
0
        public void SetRet(Result result)
        {
            if (awaiter != null)
            {
                awaiter.SetResult(result);
                awaiter.IsCompleted = true;

                Action _Continuation = awaiter.Continuation;
                awaiter = null;
                _Continuation?.Invoke();
            }
        }
コード例 #4
0
ファイル: AsyncRunBase.cs プロジェクト: 12345fish/ZYNet
        public void SetRet(ReturnResult result)
        {
            if (awaiter != null)
            {
                awaiter.SetResult(result);
                awaiter.IsCompleted = true;

                Action _Continuation = awaiter.Continuation;
                awaiter = null;

                if (_Continuation != null)
                {
                    _Continuation();
                }
            }
        }
コード例 #5
0
ファイル: Fiber.cs プロジェクト: 12345fish/ZYNet
        public ResultAwatier Send(ReturnResult data)
        {
            var GhostThread = Fiber.Current;

            if (GhostThread == null)
            {
                GhostThread = this;
            }


            var waitingGhostThread = new ResultAwatier(GhostThread);

            waitingGhostThread.Result = data;
            senders.Enqueue(waitingGhostThread);
            return(waitingGhostThread);
        }
コード例 #6
0
ファイル: Fiber.cs プロジェクト: 12345fish/ZYNet
        public ResultAwatier Set(ReturnResult data)
        {
            if (receivers.Count == 0)
            {
                var GhostThread = Fiber.Current;

                if (GhostThread == null)
                {
                    GhostThread = this;
                }

                var waitingGhostThread = new ResultAwatier(GhostThread);
                waitingGhostThread.Result = data;

                senders.Enqueue(waitingGhostThread);
                return(waitingGhostThread);
            }



            ResultAwatier tmp;

            if (receivers.TryDequeue(out tmp))
            {
                var receiver = tmp as ResultAwatier;

                receiver.Result      = data;
                receiver.IsCompleted = true;

                var previousSyncContext = SynchronizationContext.Current;
                SynchronizationContext.SetSynchronizationContext(_SynchronizationContext);
                if (receiver.Continuation != null)
                {
                    receiver.Continuation();
                }
                SynchronizationContext.SetSynchronizationContext(previousSyncContext);
                return(receiver);
            }
            else
            {
                return(null);
            }
        }