Skip to content

Instantly share code, notes, and snippets.

@kenoir
Created January 14, 2022 14:55
Show Gist options
  • Save kenoir/a8e889cb27fc0dbf2c847a1c97ccb870 to your computer and use it in GitHub Desktop.
Save kenoir/a8e889cb27fc0dbf2c847a1c97ccb870 to your computer and use it in GitHub Desktop.
sealed trait CrawledUrl { val url: URl }
case class PendingURL extends CrawledUrl(url: URL)
case class InFlightURL extends CrawledUrl(url: URL)
case class VisitedURL extends CrawledUrl(url: URL)
object UrlSource2 {
val urlStore: scala.collection.concurrent.Map[URL, CrawledUrl]
def completeTask(doneUrl: URL): Unit = {
urlStore.updateWith(doneUrl, VisitedURL(doneUrl.url))
}
def consumeTask(): Option[URL] = {
urlStore.find {
case url: PendingURL => url
} map { foundUrl
urlStore.updateWith(foundUrl, InFlightURL(doneUrl.url))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment