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); } }
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); } }
public void SetRet(Result result) { if (awaiter != null) { awaiter.SetResult(result); awaiter.IsCompleted = true; Action _Continuation = awaiter.Continuation; awaiter = null; _Continuation?.Invoke(); } }
public void SetRet(ReturnResult result) { if (awaiter != null) { awaiter.SetResult(result); awaiter.IsCompleted = true; Action _Continuation = awaiter.Continuation; awaiter = null; if (_Continuation != null) { _Continuation(); } } }
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); }
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); } }