gRPC  0.6.0
 All Classes Namespaces Functions Variables Enumerations Properties Pages
GRPCDelegateWrapper.h
1 /*
2  *
3  * Copyright 2015, Google Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above
13  * copyright notice, this list of conditions and the following disclaimer
14  * in the documentation and/or other materials provided with the
15  * distribution.
16  * * Neither the name of Google Inc. nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  */
33 
34 #import <Foundation/Foundation.h>
35 
36 @protocol GRXWriteable;
37 @protocol GRXWriter;
38 
39 // This is a thread-safe wrapper over a GRXWriteable instance. It lets one
40 // enqueue calls to a GRXWriteable instance for the main thread, guaranteeing
41 // that didFinishWithError: is the last message sent to it (no matter what
42 // messages are sent to the wrapper, in what order, nor from which thread). It
43 // also guarantees that, if cancelWithError: is called from the main thread
44 // (e.g. by the app cancelling the writes), no further messages are sent to the
45 // writeable except didFinishWithError:.
46 //
47 // TODO(jcanizales): Let the user specify another queue for the writeable
48 // callbacks.
49 // TODO(jcanizales): Rename to GRXWriteableWrapper and move to the Rx library.
50 @interface GRPCDelegateWrapper : NSObject
51 
52 // The GRXWriteable passed is the wrapped writeable.
53 // Both the GRXWriter instance and the GRXWriteable instance are retained until
54 // didFinishWithError: is sent to the writeable, and released after that.
55 // This is used to create a retain cycle that keeps both objects alive until the
56 // writing is explicitly finished.
57 - (instancetype)initWithWriteable:(id<GRXWriteable>)writeable writer:(id<GRXWriter>)writer
58  NS_DESIGNATED_INITIALIZER;
59 
60 // Enqueues didReceiveValue: to be sent to the writeable in the main thread.
61 // The passed handler is invoked from the main thread after didReceiveValue:
62 // returns.
63 - (void)enqueueMessage:(NSData *)message completionHandler:(void (^)())handler;
64 
65 // Enqueues didFinishWithError:nil to be sent to the writeable in the main
66 // thread. After that message is sent to the writeable, all other methods of
67 // this object are effectively noops.
68 - (void)enqueueSuccessfulCompletion;
69 
70 // If the writeable has not yet received a didFinishWithError: message, this
71 // will enqueue one to be sent to it in the main thread, and cancel all other
72 // pending messages to the writeable enqueued by this object (both past and
73 // future).
74 // The error argument cannot be nil.
75 - (void)cancelWithError:(NSError *)error;
76 
77 // Cancels all pending messages to the writeable enqueued by this object (both
78 // past and future). Because the writeable won't receive didFinishWithError:,
79 // this also releases the writeable and the writer.
80 - (void)cancelSilently;
81 @end
Definition: GRXWriter.h:125
Definition: GRXWriteable.h:58
Definition: GRPCDelegateWrapper.h:50