Merge pull request #3999 from eed3si9n/wip/cache-watch-service

[bport] Cache watch service
This commit is contained in:
eugene yokota 2018-03-09 17:42:11 -05:00 committed by GitHub
commit 3559de06aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 3 deletions

View File

@ -94,7 +94,7 @@ object Watched {
@tailrec def shouldTerminate: Boolean =
(System.in.available > 0) && (watched.terminateWatch(System.in.read()) || shouldTerminate)
val sources = watched.watchSources(s)
val service = watched.watchService()
val service = s get ContinuousWatchService getOrElse watched.watchService()
val watchState = s get ContinuousState getOrElse WatchState.empty(service, sources)
if (watchState.count > 0)
@ -115,15 +115,21 @@ object Watched {
if (triggered) {
printIfDefined(watched triggeredMessage newWatchState)
(ClearOnFailure :: next :: FailureWall :: repeat :: s).put(ContinuousState, newWatchState)
(ClearOnFailure :: next :: FailureWall :: repeat :: s)
.put(ContinuousState, newWatchState)
.put(ContinuousWatchService, service)
} else {
while (System.in.available() > 0) System.in.read()
service.close()
s.remove(ContinuousState)
s.remove(ContinuousState).remove(ContinuousWatchService)
}
}
val ContinuousState =
AttributeKey[WatchState]("watch state", "Internal: tracks state for continuous execution.")
val ContinuousWatchService =
AttributeKey[WatchService]("watch service",
"Internal: tracks watch service for continuous execution.")
val Configuration =
AttributeKey[Watched]("watched-configuration", "Configures continuous execution.")