content: package kotlinx.coroutines;
  
  import java.util.concurrent.Executor;
  import java.util.concurrent.ExecutorService;
  import java.util.concurrent.RejectedExecutionException;
  import java.util.concurrent.ScheduledExecutorService;
  import java.util.concurrent.ScheduledFuture;
  import java.util.concurrent.TimeUnit;
  import kotlin.Deprecated;
  import kotlin.DeprecationLevel;
  import kotlin.Metadata;
  import kotlin.Unit;
  import kotlin.coroutines.Continuation;
  import kotlin.coroutines.CoroutineContext;
  import kotlinx.coroutines.Delay;
  import kotlinx.coroutines.internal.ConcurrentKt;
  
  @Metadata(d1 = {"\u0000j\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000b\n\u0000\n\u0002\u0010\u0000\n\u0000\n\u0002\u0010\b\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\t\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000e\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\b\u0000\u0018\u00002\u00020\u00012\u00020\u0002B\r\u0012\u0006\u0010\u0003\u001a\u00020\u0004¢\u0006\u0002\u0010\u0005J\u0018\u0010\b\u001a\u00020\t2\u0006\u0010\n\u001a\u00020\u000b2\u0006\u0010\f\u001a\u00020\rH\u0002J\b\u0010\u000e\u001a\u00020\tH\u0016J\u001c\u0010\u000f\u001a\u00020\t2\u0006\u0010\n\u001a\u00020\u000b2\n\u0010\u0010\u001a\u00060\u0011j\u0002`\u0012H\u0016J\u0013\u0010\u0013\u001a\u00020\u00142\b\u0010\u0015\u001a\u0004\u0018\u00010\u0016H\u0002J\b\u0010\u0017\u001a\u00020\u0018H\u0016J$\u0010\u0019\u001a\u00020\u001a2\u0006\u0010\u001b\u001a\u00020\u001c2\n\u0010\u0010\u001a\u00060\u0011j\u0002`\u00122\u0006\u0010\n\u001a\u00020\u000bH\u0016J\u001e\u0010\u001d\u001a\u00020\t2\u0006\u0010\u001b\u001a\u00020\u001c2\f\u0010\u001e\u001a\b\u0012\u0004\u0012\u00020\t0\u001fH\u0016J\b\u0010 \u001a\u00020!H\u0016J.\u0010\"\u001a\b\u0012\u0002\b\u0003\u0018\u00010#*\u00020$2\n\u0010\u0010\u001a\u00060\u0011j\u0002`\u00122\u0006\u0010\n\u001a\u00020\u000b2\u0006\u0010\u001b\u001a\u00020\u001cH\u0002R\u0014\u0010\u0003\u001a\u00020\u0004X\u0004¢\u0006\b\n\u0000\u001a\u0004\b\u0006\u0010\u0007¨\u0006%"}, d2 = {"Lkotlinx/coroutines/ExecutorCoroutineDispatcherImpl;", "Lkotlinx/coroutines/ExecutorCoroutineDispatcher;", "Lkotlinx/coroutines/Delay;", "executor", "Ljava/util/concurrent/Executor;", "(Ljava/util/concurrent/Executor;)V", "getExecutor", "()Ljava/util/concurrent/Executor;", "cancelJobOnRejection", "", "context", "Lkotlin/coroutines/CoroutineContext;", "exception", "Ljava/util/concurrent/RejectedExecutionException;", "close", "dispatch", "block", "Ljava/lang/Runnable;", "Lkotlinx/coroutines/Runnable;", "equals", "", "other", "", "hashCode", "", "invokeOnTimeout", "Lkotlinx/coroutines/DisposableHandle;", "timeMillis", "", "scheduleResumeAfterDelay", "continuation", "Lkotlinx/coroutines/CancellableContinuation;", "toString", "", "scheduleBlock", "Ljava/util/concurrent/ScheduledFuture;", "Ljava/util/concurrent/ScheduledExecutorService;", "kotlinx-coroutines-core"}, k = 1, mv = {1, 6, 0}, xi = 48)
  /* compiled from: Executors.kt */
  public final class ExecutorCoroutineDispatcherImpl extends ExecutorCoroutineDispatcher implements Delay {
      private final Executor executor;
  
      public ExecutorCoroutineDispatcherImpl(Executor executor2) {
          this.executor = executor2;
          ConcurrentKt.removeFutureOnCancel(getExecutor());
      }
  
      private final void cancelJobOnRejection(CoroutineContext context, RejectedExecutionException exception) {
          JobKt.cancel(context, ExceptionsKt.CancellationException("The task was rejected", exception));
      }
  
      private final ScheduledFuture<?> scheduleBlock(ScheduledExecutorService $this$scheduleBlock, Runnable block, CoroutineContext context, long timeMillis) {
          try {
              return $this$scheduleBlock.schedule(block, timeMillis, TimeUnit.MILLISECONDS);
          } catch (RejectedExecutionException e) {
              cancelJobOnRejection(context, e);
              ScheduledFuture scheduledFuture = null;
              return null;
          }
      }
  
      public void close() {
          Executor executor2 = getExecutor();
          ExecutorService executorService = executor2 instanceof ExecutorService ? (ExecutorService) executor2 : null;
          if (executorService != null) {
              executorService.shutdown();
          }
      }
  
      @Deprecated(level = DeprecationLevel.ERROR, message = "Deprecated without replacement as an internal method never intended for public use")
      public Object delay(long time, Continuation<? super Unit> $completion) {
          return Delay.DefaultImpls.delay(this, time, $completion);
      }
  
      public void dispatch(CoroutineContext context, Runnable block) {
          Runnable runnable;
          try {
              Executor executor2 = getExecutor();
              AbstractTimeSource timeSource = AbstractTimeSourceKt.getTimeSource();
              if (timeSource != null) {
                  runnable = timeSource.wrapTask(block);
                  if (runnable == null) {
                  }
                  executor2.execute(runnable);
              }
              runnable = block;
              executor2.execute(runnable);
          } catch (RejectedExecutionException e) {
              AbstractTimeSource timeSource2 = AbstractTimeSourceKt.getTimeSource();
              if (timeSource2 != null) {
                  timeSource2.unTrackTask();
              }
              cancelJobOnRejection(context, e);
              Dispatchers.getIO().dispatch(context, block);
          }
      }
  
      public boolean equals(Object other) {
          return (other instanceof ExecutorCoroutineDispatcherImpl) && ((ExecutorCoroutineDispatcherImpl) other).getExecutor() == getExecutor();
      }
  
      public Executor getExecutor() {
          return this.executor;
      }
  
      public int hashCode() {
          return System.identityHashCode(getExecutor());
      }
  
      public DisposableHandle invokeOnTimeout(long timeMillis, Runnable block, CoroutineContext context) {
          Executor executor2 = getExecutor();
          ScheduledFuture<?> scheduledFuture = null;
          ScheduledExecutorService scheduledExecutorService = executor2 instanceof ScheduledExecutorService ? (ScheduledExecutorService) executor2 : null;
          if (scheduledExecutorService != null) {
              scheduledFuture = scheduleBlock(scheduledExecutorService, block, context, timeMillis);
          }
          ScheduledFuture<?> scheduledFuture2 = scheduledFuture;
          return scheduledFuture2 != null ? new DisposableFutureHandle(scheduledFuture2) : DefaultExecutor.INSTANCE.invokeOnTimeout(timeMillis, block, context);
      }
  
      public void scheduleResumeAfterDelay(long timeMillis, CancellableContinuation<? super Unit> continuation) {
          Executor executor2 = getExecutor();
          ScheduledFuture<?> scheduledFuture = null;
          ScheduledExecutorService scheduledExecutorService = executor2 instanceof ScheduledExecutorService ? (ScheduledExecutorService) executor2 : null;
          if (scheduledExecutorService != null) {
              scheduledFuture = scheduleBlock(scheduledExecutorService, new ResumeUndispatchedRunnable(this, continuation), continuation.getContext(), timeMillis);
          }
          ScheduledFuture<?> scheduledFuture2 = scheduledFuture;
          if (scheduledFuture2 != null) {
              JobKt.cancelFutureOnCancellation(continuation, scheduledFuture2);
          } else {
              DefaultExecutor.INSTANCE.scheduleResumeAfterDelay(timeMillis, continuation);
          }
      }
  
      public String toString() {
          return getExecutor().toString();
      }
  }
  