Beispiel #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);
            }
        }
Beispiel #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);
            }
        }
Beispiel #3
0
        public void SetRet(Result result)
        {
            if (awaiter != null)
            {
                awaiter.SetResult(result);
                awaiter.IsCompleted = true;

                Action _Continuation = awaiter.Continuation;
                awaiter = null;
                _Continuation?.Invoke();
            }
        }
Beispiel #4
0
        public void SetRet(ReturnResult result)
        {
            if (awaiter != null)
            {
                awaiter.SetResult(result);
                awaiter.IsCompleted = true;

                Action _Continuation = awaiter.Continuation;
                awaiter = null;

                if (_Continuation != null)
                {
                    _Continuation();
                }
            }
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        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);
            }
        }