Skip to content

Instantly share code, notes, and snippets.

@adamw
Created June 11, 2018 16:42
Show Gist options
  • Save adamw/3b585c043a7a55bfa22d9f7eaaf1cc0e to your computer and use it in GitHub Desktop.
Save adamw/3b585c043a7a55bfa22d9f7eaaf1cc0e to your computer and use it in GitHub Desktop.
val connect: Task[Queue[Task]] = Task
.eval(logger.info("[queue-start] connecting"))
.flatMap(_ => connector.connect)
.map { q =>
logger.info("[queue-start] connected")
q
}
def consumeQueue(queue: Queue[Task]): Task[Unit] =
Task
.eval(logger.info("[queue] receiving message"))
.flatMap(_ => queue.read())
.flatMap(msg => inbox.put(Received(msg)))
.cancelable
.restartUntil(_ => false)
def releaseQueue(queue: Queue[Task]): Task[Unit] =
Task
.eval(logger.info("[queue-stop] closing"))
.flatMap(_ => queue.close())
.map(_ => logger.info("[queue-stop] closed"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment