Async function gets wrong value from parameter

I sent a list of string to an async function, but it got the wrong value. Can anyone help??

from runtime.asyncrt import TaskGroup
        
async fn print_list(li: List[String]):   
    for s in li:
        print(s)

fn main():
    var li: List[String] = ["Hello", "world"]
    var tg = TaskGroup()
    tg.create_task(print_list(li))
    tg.wait()```
$ mojo life.mojo
�!࿙
world
from runtime.asyncrt import TaskGroup


async fn print_list(li: List[String]):
    for s in li:
        print(s)


fn main():
    var li: List[String] = ["Hello", "world"]
    var tg = TaskGroup()
    tg.create_task(print_list(li))
    tg.wait()
    _ = li

You need to extend the origin of li. The compiler doesn’t know yet how to deal with async that well.

As Owen mentioned in another thread, async stuff is really not ready for “normal” uses. I think it was me who posted the runtime.asyncrt stuff in Discord as a “technically this is possible”. But it’s really not supported or blessed right now and is full of issues like you’re running into here. I’d recommend not using it for anything more than testing stuff out. And if you do use it you need to basically pretend it’s just threads with no safeguards about what can be done.

As @duck_tape mentioned, async is very much not ready for anything other than people writing code to figure out how it should work. I would advise against using it for now.