Jorge Canizales | e8304d5 | 2015-02-17 19:50:51 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 3 | * Copyright 2015 gRPC authors. |
Jorge Canizales | e8304d5 | 2015-02-17 19:50:51 -0800 | [diff] [blame] | 4 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
Jorge Canizales | e8304d5 | 2015-02-17 19:50:51 -0800 | [diff] [blame] | 8 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
Jorge Canizales | e8304d5 | 2015-02-17 19:50:51 -0800 | [diff] [blame] | 10 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
Jorge Canizales | e8304d5 | 2015-02-17 19:50:51 -0800 | [diff] [blame] | 16 | * |
| 17 | */ |
| 18 | |
Jorge Canizales | 30697c9 | 2015-02-17 17:09:14 -0800 | [diff] [blame] | 19 | #import <Foundation/Foundation.h> |
| 20 | |
Jorge Canizales | b10776c | 2015-10-26 10:44:55 -0700 | [diff] [blame] | 21 | /** |
| 22 | * A GRXWriteable is an object to which a sequence of values can be sent. The |
| 23 | * sequence finishes with an optional error. |
| 24 | */ |
Jorge Canizales | 30697c9 | 2015-02-17 17:09:14 -0800 | [diff] [blame] | 25 | @protocol GRXWriteable <NSObject> |
| 26 | |
Jorge Canizales | b10776c | 2015-10-26 10:44:55 -0700 | [diff] [blame] | 27 | /** Push the next value of the sequence to the receiving object. */ |
Jorge Canizales | a90a9c3 | 2015-05-18 17:12:41 -0700 | [diff] [blame] | 28 | - (void)writeValue:(id)value; |
Jorge Canizales | 30697c9 | 2015-02-17 17:09:14 -0800 | [diff] [blame] | 29 | |
Jorge Canizales | b10776c | 2015-10-26 10:44:55 -0700 | [diff] [blame] | 30 | /** |
| 31 | * Signal that the sequence is completed, or that an error ocurred. After this |
| 32 | * message is sent to the instance, neither it nor writeValue: may be |
| 33 | * called again. |
| 34 | */ |
Jorge Canizales | b2c300c | 2015-05-18 17:19:16 -0700 | [diff] [blame] | 35 | - (void)writesFinishedWithError:(NSError *)errorOrNil; |
Jorge Canizales | 30697c9 | 2015-02-17 17:09:14 -0800 | [diff] [blame] | 36 | @end |
| 37 | |
| 38 | typedef void (^GRXValueHandler)(id value); |
| 39 | typedef void (^GRXCompletionHandler)(NSError *errorOrNil); |
Jorge Canizales | f95ddba | 2015-08-12 10:51:56 -0700 | [diff] [blame] | 40 | typedef void (^GRXSingleHandler)(id value, NSError *errorOrNil); |
| 41 | typedef void (^GRXEventHandler)(BOOL done, id value, NSError *error); |
Jorge Canizales | 30697c9 | 2015-02-17 17:09:14 -0800 | [diff] [blame] | 42 | |
Jorge Canizales | b10776c | 2015-10-26 10:44:55 -0700 | [diff] [blame] | 43 | /** |
| 44 | * Utility to create objects that conform to the GRXWriteable protocol, from |
| 45 | * blocks that handle each of the two methods of the protocol. |
| 46 | */ |
Jorge Canizales | 30697c9 | 2015-02-17 17:09:14 -0800 | [diff] [blame] | 47 | @interface GRXWriteable : NSObject<GRXWriteable> |
Jorge Canizales | 2779ccb | 2015-04-20 23:42:46 -0700 | [diff] [blame] | 48 | |
Jorge Canizales | f95ddba | 2015-08-12 10:51:56 -0700 | [diff] [blame] | 49 | + (instancetype)writeableWithSingleHandler:(GRXSingleHandler)handler; |
| 50 | + (instancetype)writeableWithEventHandler:(GRXEventHandler)handler; |
Jorge Canizales | 2779ccb | 2015-04-20 23:42:46 -0700 | [diff] [blame] | 51 | |
Jorge Canizales | 30697c9 | 2015-02-17 17:09:14 -0800 | [diff] [blame] | 52 | - (instancetype)initWithValueHandler:(GRXValueHandler)valueHandler |
| 53 | completionHandler:(GRXCompletionHandler)completionHandler |
| 54 | NS_DESIGNATED_INITIALIZER; |
| 55 | @end |