core-lightning/tests/plugins/asynctest.py
Christian Decker 7f11b4854e 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>
2019-02-22 02:59:36 +00:00

31 lines
670 B
Python
Executable File

#!/usr/bin/env python3
"""This plugin is used to check that async method calls are working correctly.
The plugin registers a method `callme` with an argument. All calls are
stashed away, and are only resolved on the fifth invocation. All calls
will then return the argument of the fifth call.
"""
from lightning import Plugin
plugin = Plugin()
@plugin.init()
def init(configuration, options, plugin):
plugin.requests = []
@plugin.async_method('asyncqueue')
def async_queue(request, plugin):
plugin.requests.append(request)
@plugin.method('asyncflush')
def async_flush(res, plugin):
for r in plugin.requests:
r.set_result(res)
plugin.run()