equal
deleted
inserted
replaced
43 |
43 |
44 # Batched call to a couple of (possibly proxied) methods. |
44 # Batched call to a couple of (possibly proxied) methods. |
45 batch = it.batch() |
45 batch = it.batch() |
46 # The calls return futures to eventually hold results. |
46 # The calls return futures to eventually hold results. |
47 foo = batch.foo(one="One", two="Two") |
47 foo = batch.foo(one="One", two="Two") |
48 foo2 = batch.foo(None) |
|
49 bar = batch.bar("Eins", "Zwei") |
48 bar = batch.bar("Eins", "Zwei") |
50 # We can call non-batchable proxy methods, but the break the current batch |
49 # We can call non-batchable proxy methods, but the break the current batch |
51 # request and cause additional roundtrips. |
50 # request and cause additional roundtrips. |
52 greet = batch.greet(name="John Smith") |
51 greet = batch.greet(name="John Smith") |
53 # We can also add local methods into the mix, but they break the batch too. |
52 # We can also add local methods into the mix, but they break the batch too. |
56 # Only now are all the calls executed in sequence, with as few roundtrips |
55 # Only now are all the calls executed in sequence, with as few roundtrips |
57 # as possible. |
56 # as possible. |
58 batch.submit() |
57 batch.submit() |
59 # After the call to submit, the futures actually contain values. |
58 # After the call to submit, the futures actually contain values. |
60 print(foo.value) |
59 print(foo.value) |
61 print(foo2.value) |
|
62 print(bar.value) |
60 print(bar.value) |
63 print(greet.value) |
61 print(greet.value) |
64 print(hello.value) |
62 print(hello.value) |
65 print(bar2.value) |
63 print(bar2.value) |
66 |
64 |
151 def batch(self): |
149 def batch(self): |
152 return wireproto.remotebatch(self) |
150 return wireproto.remotebatch(self) |
153 |
151 |
154 @peer.batchable |
152 @peer.batchable |
155 def foo(self, one, two=None): |
153 def foo(self, one, two=None): |
156 if not one: |
|
157 yield "Nope", None |
|
158 encargs = [('one', mangle(one),), ('two', mangle(two),)] |
154 encargs = [('one', mangle(one),), ('two', mangle(two),)] |
159 encresref = peer.future() |
155 encresref = peer.future() |
160 yield encargs, encresref |
156 yield encargs, encresref |
161 yield unmangle(encresref.value) |
157 yield unmangle(encresref.value) |
162 |
158 |