resolvWorker
  :: forall e
   . HasLogFunc e
  => Galaxy
  -> TVar (Maybe [Turf])
  -> TVar (Time.Wen, Maybe SockAddr)
  -> STM ByteString
  -> (SockAddr -> ByteString -> IO  ())
  -> (Text -> RIO e ())
  -> RIO e (Async ())
resolvWorker gal vTurfs vLast waitMsg send stderr = async (forever go)
 where
  logDrop =
    logInfo $ displayShow ("(ames) Dropping packet; no ip for galaxy ", gal)

  go :: RIO e ()
  go = do
    (packt, turfs, (lastTime, lastAddr)) <- atomically
      ((,,) <$> waitMsg <*> readTVar vTurfs <*> readTVar vLast)

    (newAddr, newTime) <- doResolv gal
                                   (lastTime, lastAddr)
                                   (fromMaybe [] turfs)
                                   stderr

    maybe logDrop (\ip -> io (send ip packt)) newAddr

    atomically $ writeTVar vLast (newTime, newAddr)
resolvWorker
  :: forall e
   . HasLogFunc e
  => Galaxy
  -> TVar (Maybe [Turf])
  -> TVar (Time.Wen, Maybe SockAddr)
  -> STM ByteString
  -> (SockAddr -> ByteString -> IO  ())
  -> (Text -> RIO e ())
  -> RIO e (Async ())
resolvWorker gal vTurfs vLast waitMsg send stderr = async (forever go)
 where
  logDrop =
    logInfo $ displayShow ("(ames) Dropping packet; no ip for galaxy ", gal)

  go :: RIO e ()
  go = do
    (packt, turfs, (lastTime, lastAddr)) <- atomically
      ((,,) <$> waitMsg <*> readTVar vTurfs <*> readTVar vLast)

    (newAddr, newTime) <- doResolv gal
                                   (lastTime, lastAddr)
                                   (fromMaybe [] turfs)
                                   stderr

    maybe logDrop (\ip -> io (send ip packt)) newAddr

    atomically $ writeTVar vLast (newTime, newAddr)
resolvWorker gal vTurfs vLast waitMsg send stderr = async (forever go)
 where
  logDrop =
    logInfo $ displayShow ("(ames) Dropping packet; no ip for galaxy ", gal)

  go :: RIO e ()
  go = do
    (packt, turfs, (lastTime, lastAddr)) <- atomically
      ((,,) <$> waitMsg <*> readTVar vTurfs <*> readTVar vLast)

    (newAddr, newTime) <- doResolv gal
                                   (lastTime, lastAddr)
                                   (fromMaybe [] turfs)
                                   stderr

    maybe logDrop (\ip -> io (send ip packt)) newAddr

    atomically $ writeTVar vLast (newTime, newAddr)