mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-12-26 19:18:12 +01:00
Make it even clearer that the listener loop method should be
called from a separate thread.
This commit is contained in:
parent
025e97ca95
commit
4f4202185c
@ -86,12 +86,22 @@ public class AsyncListenerHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point for the background thread that will be processing the packet asynchronously.
|
||||
* Create a runnable that will initiate the listener loop.
|
||||
* <p>
|
||||
* <b>WARNING:</b>
|
||||
* Never call this method from the main thread. Doing so will block Minecraft.
|
||||
* <b>Warning</b>: Never call the run() method in the main thread.
|
||||
*/
|
||||
public void listenerLoop() {
|
||||
public Runnable getListenerLoop() {
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
listenerLoop();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// DO NOT call this method from the main thread
|
||||
private void listenerLoop() {
|
||||
|
||||
// Danger, danger!
|
||||
if (Thread.currentThread().getId() == mainThread.getId())
|
||||
throw new IllegalStateException("Do not call this method from the main thread.");
|
||||
|
@ -27,7 +27,13 @@ class PacketSendingQueue {
|
||||
public synchronized void signalPacketUpdate(PacketEvent packetUpdated) {
|
||||
// Mark this packet as finished
|
||||
packetUpdated.getAsyncMarker().setProcessed(true);
|
||||
trySendPackets();
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to send any remaining packets.
|
||||
*/
|
||||
public synchronized void trySendPackets() {
|
||||
// Transmit as many packets as we can
|
||||
while (true) {
|
||||
PacketEvent current = sendingQueue.peek();
|
||||
|
Loading…
Reference in New Issue
Block a user