Created
March 20, 2016 01:14
-
-
Save ktoso/f1ed5157b61552a5ae3d to your computer and use it in GitHub Desktop.
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
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