Async callback in param.Action

hi
how can i put an async callback to a param of type Action ?
thanks

class Test(param.Parameterized):
    async def _action_cb(self):
        await asyncio.sleep(1)
        print('action_cb', self.data)

    def panel(self):
        return pn.Param(
            self,
            widgets={
                'data': {
                    'widget_type': pn.widgets.JSONEditor,
                    'menu': False,
                    'search': False,
                    'mode': 'form',
                    'sizing_mode': 'stretch_both',
                },
            },
        )

    data = param.Dict()
    action = param.Action(_action_cb)

obj = Test()
gui = obj.panel()
gui.show()

RuntimeWarning: coroutine ‘Test._action_cb’ was never awaited
value(self.object)

I don’t understand why that doesn’t work, but this one does seem to work:

class Test(param.Parameterized):

    data = param.Dict()
    action = param.Event()

    @param.depends('action', watch = True)
    async def _action_cb(self):
        await asyncio.sleep(1)
        print('action_cb', self.data)

    def panel(self):
        return pn.Param(
            self,
            widgets={
                'data': {
                    'widget_type': pn.widgets.JSONEditor,
                    'menu': False,
                    'search': False,
                    'mode': 'form',
                    'sizing_mode': 'stretch_both',
                },
            },
        )

obj = Test()
gui = obj.panel()
gui.show()
2 Likes