main :: IO ()
main = do
  args <- getArgs
  print args
  globalState <- newGlobalState 8035
  torrents <- traverse openTorrentFile args
  rpcServer <- async $ scotty 8036 (RPC.server globalState)
  listener <- btListen globalState
  traverse_ (forkIO . runTorrent globalState) (catMaybes torrents)
  void $ installHandler sigINT (CatchOnce (cancel listener *> cancel rpcServer)) Nothing
  void $ forkIO $ progressLogger globalState
  void $ forkIO $ periodicCheckup globalState
  (do wait listener
      wait rpcServer)
    `finally` cleanup globalState
main :: IO ()
main = do
  args <- getArgs
  print args
  globalState <- newGlobalState 8035
  torrents <- traverse openTorrentFile args
  rpcServer <- async $ scotty 8036 (RPC.server globalState)
  listener <- btListen globalState
  traverse_ (forkIO . runTorrent globalState) (catMaybes torrents)
  void $ installHandler sigINT (CatchOnce (cancel listener *> cancel rpcServer)) Nothing
  void $ forkIO $ progressLogger globalState
  void $ forkIO $ periodicCheckup globalState
  (do wait listener
      wait rpcServer)
    `finally` cleanup globalState
main = do
  args <- getArgs
  print args
  globalState <- newGlobalState 8035
  torrents <- traverse openTorrentFile args
  rpcServer <- async $ scotty 8036 (RPC.server globalState)
  listener <- btListen globalState
  traverse_ (forkIO . runTorrent globalState) (catMaybes torrents)
  void $ installHandler sigINT (CatchOnce (cancel listener *> cancel rpcServer)) Nothing
  void $ forkIO $ progressLogger globalState
  void $ forkIO $ periodicCheckup globalState
  (do wait listener
      wait rpcServer)
    `finally` cleanup globalState