-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
=htc small refactoring in OneHundredContinue support
- Loading branch information
Showing
3 changed files
with
100 additions
and
97 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
akka-http-core/src/main/scala/akka/http/engine/TokenSourceActor.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package akka.http.engine | ||
|
||
import scala.annotation.tailrec | ||
import akka.stream.actor.{ ActorPublisherMessage, ActorPublisher } | ||
|
||
/** | ||
* An actor publisher for producing a simple stream of singleton tokens | ||
* the release of which is triggered by the reception of a [[TokenSourceActor.Trigger]] message. | ||
*/ | ||
private[engine] class TokenSourceActor[T](token: T) extends ActorPublisher[T] { | ||
private var triggered = 0 | ||
|
||
def receive = { | ||
case TokenSourceActor.Trigger ⇒ | ||
triggered += 1 | ||
tryDispatch() | ||
|
||
case ActorPublisherMessage.Request(_) ⇒ | ||
tryDispatch() | ||
|
||
case ActorPublisherMessage.Cancel ⇒ | ||
context.stop(self) | ||
} | ||
|
||
@tailrec private def tryDispatch(): Unit = | ||
if (triggered > 0 && totalDemand > 0) { | ||
onNext(token) | ||
triggered -= 1 | ||
tryDispatch() | ||
} | ||
} | ||
|
||
private[engine] object TokenSourceActor { | ||
case object Trigger | ||
} |
This file contains 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
66 changes: 0 additions & 66 deletions
66
akka-http-core/src/main/scala/akka/http/engine/server/OneHundredContinue.scala
This file was deleted.
Oops, something went wrong.