mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-23 00:54:20 +01:00
pylightning: Add a small test for async rpcmethods
Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
committed by
Rusty Russell
parent
cc4fbfca43
commit
571fb44d20
30
tests/plugins/asynctest.py
Executable file
30
tests/plugins/asynctest.py
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/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.method('asyncqueue', sync=False)
|
||||
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()
|
||||
Reference in New Issue
Block a user