Debian Codegraph @

src/objective-c/RxLibrary/GRXWriteable.h

raw
1 /*
2 *
3 * Copyright 2015 gRPC authors.
4 *
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
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
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.
16 *
17 */
18
19 #import <Foundation/Foundation.h>
20
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 */
25 @protocol GRXWriteable <NSObject>
26
27 /** Push the next value of the sequence to the receiving object. */
28 - (void)writeValue:(id)value;
29
30 /**
31 * Signal that the sequence is completed, or that an error occurred. After this
32 * message is sent to the instance, neither it nor writeValue: may be
33 * called again.
34 */
35 - (void)writesFinishedWithError:(NSError *)errorOrNil;
36 @end
37
38 typedef void (^GRXValueHandler)(id value);
39 typedef void (^GRXCompletionHandler)(NSError *errorOrNil);
40 typedef void (^GRXSingleHandler)(id value, NSError *errorOrNil);
41 typedef void (^GRXEventHandler)(BOOL done, id value, NSError *error);
42
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 */
47 @interface GRXWriteable : NSObject <GRXWriteable>
48
49 + (instancetype)writeableWithSingleHandler:(GRXSingleHandler)handler;
50 + (instancetype)writeableWithEventHandler:(GRXEventHandler)handler;
51
52 - (instancetype)initWithValueHandler:(GRXValueHandler)valueHandler
53 completionHandler:(GRXCompletionHandler)completionHandler
54 NS_DESIGNATED_INITIALIZER;
55 @end