Created
January 14, 2022 14:55
-
-
Save kenoir/a8e889cb27fc0dbf2c847a1c97ccb870 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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