public IEnumerator <YieldInstruction> Update() { var count = 0; while (cancelSource == null || !cancelSource.Token.IsCancellationRequested) { bool isStartNotify = false; lock (this){ isStartNotify = isStartNotifyRequested; } if (isStartNotify) { onStart(cancelSource); } do { AcceptData acceptData = null; lock (this){ acceptData = accepted.Count > 0 ? accepted.Dequeue() : null; count = accepted.Count; } if (acceptData != null) { onConnect?.Invoke(acceptData.connectionIndex, acceptData.sender); } } while(count > 0); yield return(new WaitForEndOfFrame()); } }
public void Accept(int connectionIndex, MessageHandler sender) { var data = new AcceptData(); data.connectionIndex = connectionIndex; data.sender = sender; lock (this){ accepted.Enqueue(data); } }