# Class AsyncRunner

java.lang.Object
it.polimi.ingsw.is25am31.network.AsyncRunner

public class AsyncRunner extends Object
The `AsyncRunner` class provides a utility for executing tasks asynchronously using a single-threaded `ExecutorService`. This ensures that tasks are processed sequentially, preventing potential concurrency issues when updating shared resources or dispatching events that require a specific order.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static interface`
  `AsyncRunner.SafeRunnable`
  A functional interface similar to `Runnable`, but allows for methods that can throw `Exception`.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `AsyncRunner()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `CompletableFuture<Void>`
  `run(AsyncRunner.SafeRunnable task)`
  Submits a `AsyncRunner.SafeRunnable` task for asynchronous execution.
  `void`
  `shutdown()`
  Initiates an orderly shutdown of the executor service.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### AsyncRunner

    public AsyncRunner()

- ## Method Details

  - ### run

    public CompletableFuture<Void> run(AsyncRunner.SafeRunnable task)
    Submits a `AsyncRunner.SafeRunnable` task for asynchronous execution. The task will be executed by the internal single-threaded executor.
    Parameters:
      `task` - The `AsyncRunner.SafeRunnable` task to be executed. This is a functional interface that allows for throwing checked exceptions.
    Returns:
      A `CompletableFuture<Void>` representing the completion of the task.

  - ### shutdown

    public void shutdown()
    Initiates an orderly shutdown of the executor service. Previously submitted tasks are executed, but no new tasks will be accepted.