Record Class NetworkRegistry.EventLoopSynchronizedWorkHandler<T>

java.lang.Object
java.lang.Record
net.neoforged.neoforge.network.registration.NetworkRegistry.EventLoopSynchronizedWorkHandler<T>
Record Components:
eventLoop - The event loop to schedule tasks on.
All Implemented Interfaces:
ISynchronizedWorkHandler
Enclosing class:
NetworkRegistry

private static record NetworkRegistry.EventLoopSynchronizedWorkHandler<T>(ReentrantBlockableEventLoop<?> eventLoop, T payload) extends Record implements ISynchronizedWorkHandler
An ISynchronizedWorkHandler that can be used to schedule tasks on the main thread of the server or client. This wrapper record is used to line up the APIs of the ReentrantBlockableEventLoop with the ISynchronizedWorkHandler.
  • Field Details

    • eventLoop

      private final ReentrantBlockableEventLoop<?> eventLoop
      The field for the eventLoop record component.
    • payload

      private final T payload
      The field for the payload record component.
    • LOGGER

      private static final org.slf4j.Logger LOGGER
  • Constructor Details

    • EventLoopSynchronizedWorkHandler

      private EventLoopSynchronizedWorkHandler(ReentrantBlockableEventLoop<?> eventLoop, T payload)
      Creates an instance of a EventLoopSynchronizedWorkHandler record class.
      Parameters:
      eventLoop - the value for the eventLoop record component
      payload - the value for the payload record component
  • Method Details

    • execute

      public void execute(Runnable task)
      Executes a task on the main thread of the game.

      The runnable task is protected against exceptions, and any exceptions thrown will be logged.

      Specified by:
      execute in interface ISynchronizedWorkHandler
      Parameters:
      task - The task to run.
    • submitAsync

      public CompletableFuture<Void> submitAsync(Runnable task)
      Submits the given work to be run synchronously on the main thread of the game.

      This method will not be guarded against exceptions.
      If you need to guard against exceptions, call CompletableFuture.exceptionally(Function), CompletableFuture.exceptionallyAsync(Function)}, or derivatives on the returned future.

      Specified by:
      submitAsync in interface ISynchronizedWorkHandler
      Parameters:
      task - The task to run.
    • submitAsync

      public <R> CompletableFuture<R> submitAsync(Supplier<R> task)
      Submits the given work to be run synchronously on the main thread of the game.

      This method will not be guarded against exceptions.
      If you need to guard against exceptions, call CompletableFuture.exceptionally(Function), CompletableFuture.exceptionallyAsync(Function)}, or derivatives on the returned future.

      Specified by:
      submitAsync in interface ISynchronizedWorkHandler
      Parameters:
      task - The task to run.
      Returns:
      A future which will complete when the task has been run.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • eventLoop

      public ReentrantBlockableEventLoop<?> eventLoop()
      Returns the value of the eventLoop record component.
      Returns:
      the value of the eventLoop record component
    • payload

      public T payload()
      Returns the value of the payload record component.
      Returns:
      the value of the payload record component