close
Skip to content

bug: Tasks created by Page.run_task can not be awaited #6515

@jnsh

Description

@jnsh

Duplicate Check

Describe the bug

The Page.create_task returns a Future object of concurrent.futures.Future type. This type of Future object is not awaitble.

As awaiting is often essential with asynchronous applications, it would be nice if the run_task could return an awaitable type, such as asyncio.Future or asyncio.Task.

It is possible to use Page.loop.create_future() or Page.loop.create_task() to get awaitable Task or Future objects, but somehow those do not seem to integrate with Flet event loop as well as Page.create_task, as sometimes the UI does not update as expected.

Code sample

Code
import flet as ft


async def main(page: ft.Page):

    async def coro():
        pass

    # works
    loop_create_task = page.loop.create_task(coro())
    print("awaiting page.loop.create_task, type:", type(loop_create_task))
    await loop_create_task
    print("awaited successfully\n")

    # works
    loop_create_future = page.loop.create_future()
    print("awaiting page.loop.create_future, type:", type(loop_create_future))
    loop_create_future.set_result(None)
    await loop_create_future
    print("awaited successfully\n")

    # fails
    page_run_task = page.run_task(coro)
    print("awaiting page.run_task, type:", type(page_run_task))
    await page_run_task
    print("awaited successfully\n")


ft.run(main)

To reproduce

  1. Create task with Page.run_task
  2. Try to await the returned Future

Expected behavior

No response

Screenshots / Videos

No response

Operating System

Linux

Operating system details

Arch Linux

Flet version

0.85.1

Regression

I'm not sure / I don't know

Suggestions

No response

Logs

Additional details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions