Skip to content

Instantly share code, notes, and snippets.

@ktoso
Created March 20, 2016 01:14
Show Gist options
  • Save ktoso/f1ed5157b61552a5ae3d to your computer and use it in GitHub Desktop.
Save ktoso/f1ed5157b61552a5ae3d to your computer and use it in GitHub Desktop.
implicit class flowTweaks[M](val wsInput: Source[Message, M]) {
def forceTextStrict: Source[Strict, M] = wsInput
.collect {
case TextMessage.Strict(text) ⇒ Future.successful(text)
case TextMessage.Streamed(textStream) ⇒ textStream.runFold("")(_ + _)
case BinaryMessage.Strict(binary) ⇒ Skip
case BinaryMessage.Streamed(binaryStream) ⇒ binaryStream.runWith(Sink.ignore); Skip
}
.filterNot(_ == Skip)
.mapAsync(1)(ConstantFun.scalaIdentityFunction)
.map(TextMessage.Strict)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment