Skip to content

Commit

Permalink
Support async functions on ParamMethod/ParamFunction (#2964)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored Nov 30, 2021
1 parent 1d03ef4 commit d6b315f
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions panel/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@
Defines the Param pane which converts Parameterized classes into a
set of widgets.
"""
import inspect
import itertools
import json
import os
import sys
import json
import types
import inspect
import itertools

from collections import OrderedDict, defaultdict, namedtuple
from contextlib import contextmanager
from functools import partial
from six import string_types

import param

from param.parameterized import classlist, discard_events

from .io import init_doc, state
from .io.server import async_execute
from .layout import Column, Panel, Row, Spacer, Tabs
from .pane.base import PaneBase, ReplacementPane
from .util import (
Expand Down Expand Up @@ -748,6 +750,13 @@ def eval(self, function):
kwargs = {n: getattr(dep.owner, dep.name) for n, dep in kw_deps.items()}
return function(*args, **kwargs)

async def _eval_async(self, awaitable):
try:
new_object = await awaitable
self._update_inner(new_object)
finally:
self._inner_layout.loading = False

def _replace_pane(self, *args, force=False):
self._evaled = bool(self._models) or force or not self.lazy
if self._evaled:
Expand All @@ -757,6 +766,9 @@ def _replace_pane(self, *args, force=False):
new_object = Spacer()
else:
new_object = self.eval(self.object)
if inspect.isawaitable(new_object):
async_execute(partial(self._eval_async, new_object))
return
self._update_inner(new_object)
finally:
self._inner_layout.loading = False
Expand Down

0 comments on commit d6b315f

Please sign in to comment.