public void Recycle(bool discard_excess_resources, Action <bool> on_finished) { if (Recycler != null && !Recycler.IsRecycling) { on_finished += on_recycled; Recycler.Recycle(part, discard_excess_resources, on_finished); } }
public void Recycle(bool discard_excess_resources, Action <bool> on_finished) { if (Recycler == null || Recycler.IsRecycling) { return; } on_finished += on_recycled; Recycler.Recycle(part, discard_excess_resources, on_finished); }
/// <summary> /// Dispatch all events waiting in the queue to event handlers /// </summary> /// <remarks>Returns true if any invocation caused an error</remarks> public bool DispatchEvents(DateTime?utcNow = null) { PreDispatchLog(utcNow ?? DateTime.UtcNow); var error = false; using (var events = _queuedEvents.Lock()) { var queuedEvents = events.Value; for (var i = 0; i < queuedEvents.Count; i++) { var e = queuedEvents[i]; switch (e.Type) { case EventType.PlayerJoined: error |= InvokeEvent(e.PlayerName, e.CodecSettings, PlayerJoined); break; case EventType.PlayerLeft: error |= InvokeEvent(e.PlayerName, PlayerLeft); break; case EventType.PlayerStartedSpeaking: error |= InvokeEvent(e.PlayerName, PlayerStartedSpeaking); break; case EventType.PlayerStoppedSpeaking: error |= InvokeEvent(e.PlayerName, PlayerStoppedSpeaking); break; case EventType.VoiceData: error |= InvokeEvent(e.VoicePacket, VoicePacketReceived); _pendingVoicePackets--; // Recycle channel buffer if (e.VoicePacket.Channels != null) { e.VoicePacket.Channels.Clear(); _channelsListPool.Recycle(e.VoicePacket.Channels); } // Recycle voice data buffer var arr = e.VoicePacket.EncodedAudioFrame.Array; if (arr != null) { using (var locker = _byteArrayPool.Lock()) locker.Value.Put(arr); } break; case EventType.TextMessage: error |= InvokeEvent(e.TextMessage, TextMessageReceived); break; case EventType.PlayerEnteredRoom: var evtEnter = CreateRoomEvent(e, true); error |= InvokeEvent(evtEnter, PlayerEnteredRoom); break; case EventType.PlayerExitedRoom: var evtExit = CreateRoomEvent(e, false); error |= InvokeEvent(evtExit, PlayerExitedRoom); break; //ncrunch: no coverage start (Justification: It's a sanity check, we shouldn't ever hit this line) default: throw new ArgumentOutOfRangeException(); //ncrunch: no coverage end } } queuedEvents.Clear(); return(error); } }
/// <summary> /// Dispatch all events waiting in the queue to event handlers /// </summary> /// <remarks>Returns true if any invocation caused an error</remarks> public bool DispatchEvents() { var error = false; using (var events = _queuedEvents.Lock()) { var queuedEvents = events.Value; for (var i = 0; i < queuedEvents.Count; i++) { var e = queuedEvents[i]; switch (e.Type) { case EventType.PlayerJoined: error |= InvokeEvent(e.PlayerName, PlayerJoined); break; case EventType.PlayerLeft: error |= InvokeEvent(e.PlayerName, PlayerLeft); break; case EventType.PlayerStartedSpeaking: error |= InvokeEvent(e.PlayerName, PlayerStartedSpeaking); break; case EventType.PlayerStoppedSpeaking: error |= InvokeEvent(e.PlayerName, PlayerStoppedSpeaking); break; case EventType.VoiceData: error |= InvokeEvent(e.VoicePacket, VoicePacketReceived); //The voice packet event is special. It has some components which need to be recycled. Do that here if (e.VoicePacket.Channels != null) { e.VoicePacket.Channels.Clear(); _channelsListPool.Recycle(e.VoicePacket.Channels); } _byteArrayPool.Recycle(e.VoicePacket.EncodedAudioFrame.Array); break; case EventType.TextMessage: error |= InvokeEvent(e.TextMessage, TextMessageReceived); break; case EventType.PlayerEnteredRoom: var evtEnter = CreateRoomEvent(e, true); error |= InvokeEvent(evtEnter, PlayerEnteredRoom); break; case EventType.PlayerExitedRoom: var evtExit = CreateRoomEvent(e, false); error |= InvokeEvent(evtExit, PlayerExitedRoom); break; //ncrunch: no coverage start (Justification: It's a sanity check, we shouldn't ever hit this line) default: throw new ArgumentOutOfRangeException(); //ncrunch: no coverage end } } queuedEvents.Clear(); return(error); } }