blob: d150bc849c6af6b3ae4d918e1a1cff4a2589baf2 [file] [log] [blame]
Jorge Canizalese8304d52015-02-17 19:50:51 -08001/*
2 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003 * Copyright 2015 gRPC authors.
Jorge Canizalese8304d52015-02-17 19:50:51 -08004 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02005 * 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 Canizalese8304d52015-02-17 19:50:51 -08008 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009 * http://www.apache.org/licenses/LICENSE-2.0
Jorge Canizalese8304d52015-02-17 19:50:51 -080010 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +020011 * 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 Canizalese8304d52015-02-17 19:50:51 -080016 *
17 */
18
Jorge Canizales30697c92015-02-17 17:09:14 -080019#import <Foundation/Foundation.h>
20
Jorge Canizalesb10776c2015-10-26 10:44:55 -070021/**
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 Canizales30697c92015-02-17 17:09:14 -080025@protocol GRXWriteable <NSObject>
26
Jorge Canizalesb10776c2015-10-26 10:44:55 -070027/** Push the next value of the sequence to the receiving object. */
Jorge Canizalesa90a9c32015-05-18 17:12:41 -070028- (void)writeValue:(id)value;
Jorge Canizales30697c92015-02-17 17:09:14 -080029
Jorge Canizalesb10776c2015-10-26 10:44:55 -070030/**
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 Canizalesb2c300c2015-05-18 17:19:16 -070035- (void)writesFinishedWithError:(NSError *)errorOrNil;
Jorge Canizales30697c92015-02-17 17:09:14 -080036@end
37
38typedef void (^GRXValueHandler)(id value);
39typedef void (^GRXCompletionHandler)(NSError *errorOrNil);
Jorge Canizalesf95ddba2015-08-12 10:51:56 -070040typedef void (^GRXSingleHandler)(id value, NSError *errorOrNil);
41typedef void (^GRXEventHandler)(BOOL done, id value, NSError *error);
Jorge Canizales30697c92015-02-17 17:09:14 -080042
Jorge Canizalesb10776c2015-10-26 10:44:55 -070043/**
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 Canizales30697c92015-02-17 17:09:14 -080047@interface GRXWriteable : NSObject<GRXWriteable>
Jorge Canizales2779ccb2015-04-20 23:42:46 -070048
Jorge Canizalesf95ddba2015-08-12 10:51:56 -070049+ (instancetype)writeableWithSingleHandler:(GRXSingleHandler)handler;
50+ (instancetype)writeableWithEventHandler:(GRXEventHandler)handler;
Jorge Canizales2779ccb2015-04-20 23:42:46 -070051
Jorge Canizales30697c92015-02-17 17:09:14 -080052- (instancetype)initWithValueHandler:(GRXValueHandler)valueHandler
53 completionHandler:(GRXCompletionHandler)completionHandler
54 NS_DESIGNATED_INITIALIZER;
55@end