-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove type-level difference of single/multiple
- Loading branch information
1 parent
30c4138
commit 92a3610
Showing
11 changed files
with
188 additions
and
207 deletions.
There are no files selected for viewing
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
48 changes: 48 additions & 0 deletions
48
modules/client/src/main/scala/rx/redis/pipeline/OperatorDecode.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,48 @@ | ||
/* | ||
* Copyright 2014 – 2015 Paul Horn | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package rx.redis.pipeline | ||
|
||
import rx.redis.pipeline.OperatorDecode.SubscriberDecode | ||
import rx.redis.resp.RespType | ||
import rx.redis.serialization.{ DecodeException, Reads } | ||
|
||
import rx.Observable.Operator | ||
import rx.Subscriber | ||
|
||
import scala.util.control.NonFatal | ||
|
||
final class OperatorDecode[A, B](A: Reads.Aux[A, B]) extends Operator[B, RespType] { | ||
def call(downstream: Subscriber[_ >: B]): Subscriber[RespType] = | ||
new SubscriberDecode[A, B](downstream, A) | ||
} | ||
object OperatorDecode { | ||
final class SubscriberDecode[A, B](downstream: Subscriber[_ >: B], A: Reads.Aux[A, B]) extends Subscriber[RespType] { | ||
def onNext(x: RespType): Unit = try { | ||
A.read | ||
.andThen(_.foreach(downstream.onNext)) | ||
.applyOrElse(x, (x: RespType) ⇒ downstream.onError(DecodeException[A](x))) | ||
} catch { | ||
case NonFatal(ex) ⇒ downstream.onError(DecodeException[A](x, ex)) | ||
} | ||
|
||
def onError(e: Throwable): Unit = | ||
downstream.onError(e) | ||
|
||
def onCompleted(): Unit = | ||
downstream.onCompleted() | ||
} | ||
} |
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
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
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
Oops, something went wrong.