Skip to content

Commit

Permalink
add global context for session (flet-dev#2934)
Browse files Browse the repository at this point in the history
* add global context for session

* export context
  • Loading branch information
50Bytes-dev committed May 18, 2024
1 parent d4cc8cd commit 2caf560
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions sdk/python/packages/flet-core/src/flet_core/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ def wrapper(*args, **kwargs):
return wrapper

def run_task(self, handler: Callable[..., Awaitable[Any]], *args, **kwargs):
_session_page.set(self)
assert asyncio.iscoroutinefunction(handler)

handler_with_context = self.__context_wrapper(handler)
Expand All @@ -543,6 +544,13 @@ def _on_completion(f):

return future

def __context_wrapper(self, handler):
def wrapper(*args):
_session_page.set(self)
handler(*args)

return wrapper

def run_thread(self, handler, *args):
handler_with_context = self.__context_wrapper(handler)
if is_pyodide():
Expand Down

0 comments on commit 2caf560

Please sign in to comment.