comparison mercurial/peer.py @ 33766:4c706037adef

wireproto: overhaul iterating batcher code (API) The remote batching code is difficult to read. Let's improve it. As part of the refactor, the future returned by method calls on batchiter() instances is now populated. However, you still need to consume the results() generator for the future to be set. But at least now we can stuff the future somewhere and not have to worry about aligning method call order with result order since you can use a future to hold the result. Also as part of the change, we now verify that @batchable generators yield exactly 2 values. In other words, we enforce their API. The non-iter batcher has been unused since b6e71f8af5b8. And to my surprise we had no explicit unit test coverage of it! test-batching.py has been overhauled to use the iterating batcher. Since the iterating batcher doesn't allow non-batchable method calls nor local calls, tests have been updated to reflect reality. The iterating batcher has been used for multiple releases apparently without major issue. So this shouldn't cause alarm. .. api:: @peer.batchable functions must now yield exactly 2 values Differential Revision: https://phab.mercurial-scm.org/D319
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 09 Aug 2017 23:29:30 -0700
parents e2fc2122029c
children b47fe9733d76
comparison
equal deleted inserted replaced
33765:e2fc2122029c 33766:4c706037adef
67 # submit for a local iter batcher is a noop 67 # submit for a local iter batcher is a noop
68 pass 68 pass
69 69
70 def results(self): 70 def results(self):
71 for name, args, opts, resref in self.calls: 71 for name, args, opts, resref in self.calls:
72 yield getattr(self.local, name)(*args, **opts) 72 resref.set(getattr(self.local, name)(*args, **opts))
73 yield resref.value
73 74
74 def batchable(f): 75 def batchable(f):
75 '''annotation for batchable methods 76 '''annotation for batchable methods
76 77
77 Such methods must implement a coroutine as follows: 78 Such methods must implement a coroutine as follows: