pylightning: Split @method and @async_method decorators

Suggested-by: Rusty Russell <@rustyrussell>
Suggested-by: Conor Scott <@conscott>
Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker 2019-02-21 15:22:07 +01:00 committed by Rusty Russell
parent d9c3f5ec4b
commit 7f11b4854e
2 changed files with 25 additions and 5 deletions

View File

@ -214,13 +214,23 @@ class Plugin(object):
else:
return self.options[name]['default']
def method(self, method_name, background=True):
def async_method(self, method_name):
"""Decorator to add an async plugin method to the dispatch table.
Internally uses add_method.
"""
def decorator(f):
self.add_method(method_name, f, background=True)
return f
return decorator
def method(self, method_name):
"""Decorator to add a plugin method to the dispatch table.
Internally uses add_method.
"""
def decorator(f):
self.add_method(method_name, f, background=background)
self.add_method(method_name, f, background=False)
return f
return decorator
@ -235,13 +245,23 @@ class Plugin(object):
method.background = background
self.methods[name] = method
def hook(self, method_name, background=False):
def hook(self, method_name):
"""Decorator to add a plugin hook to the dispatch table.
Internally uses add_hook.
"""
def decorator(f):
self.add_hook(method_name, f, background=background)
self.add_hook(method_name, f, background=False)
return f
return decorator
def async_hook(self, method_name):
"""Decorator to add an async plugin hook to the dispatch table.
Internally uses add_hook.
"""
def decorator(f):
self.add_hook(method_name, f, background=True)
return f
return decorator

View File

@ -16,7 +16,7 @@ def init(configuration, options, plugin):
plugin.requests = []
@plugin.method('asyncqueue', sync=False)
@plugin.async_method('asyncqueue')
def async_queue(request, plugin):
plugin.requests.append(request)