samufi
samufi
MModular
Created by samufi on 8/2/2024 in #questions
How can I write asynchronous code?
Thanks, this is very helpful!
11 replies
MModular
Created by samufi on 8/2/2024 in #questions
How can I write asynchronous code?
Hmmm, it still looks not asynchroneous...
async fn get_time() -> Float64:
var time = now() * 1e-9
sleep(1)
return time

fn call_it():
var a = get_time()
var b = get_time()

print(await a^)
print(await b^)
async fn get_time() -> Float64:
var time = now() * 1e-9
sleep(1)
return time

fn call_it():
var a = get_time()
var b = get_time()

print(await a^)
print(await b^)
If we call call_it, we get
6916.1215625790001 6917.1220518390001
So the functions are not executed in parallel. It seems as if it is waited until await is called. So what am I doing wrong? How could I achive asynchonity?
11 replies
MModular
Created by samufi on 8/2/2024 in #questions
How can I write asynchronous code?
I was pointed to the answer in a different channel. I need to "delete" the coroutine when waiting for it.
async fn add_three(a: Int, b: Int, c: Int) -> Int:
return a + b + c

async fn call_it():
var task = add_three(1, 2, 3)
print(await task^)
async fn add_three(a: Int, b: Int, c: Int) -> Int:
return a + b + c

async fn call_it():
var task = add_three(1, 2, 3)
print(await task^)
11 replies
MModular
Created by samufi on 8/2/2024 in #questions
How can I write asynchronous code?
Or am I simply doing it wrong? (Anyone here who has used async in mojo??)
11 replies
MModular
Created by samufi on 8/2/2024 in #questions
How can I write asynchronous code?
Any updates on this yet @Ehsan M. Kermani ? The issue is still there in the current nightly.
11 replies
MModular
Created by samufi on 8/5/2024 in #questions
Is there a (N-D) contiguous data structure for non-trivial structs?
Then the only remaining question would be which container provides inline-vector-like functionality but can hold tuples and implements CollectionElement
6 replies
MModular
Created by samufi on 8/5/2024 in #questions
Is there a (N-D) contiguous data structure for non-trivial structs?
Yes, I think in principle, List is not too bad for the "outer" array (except that I need to wrap it into a 2D structure around for simple access). I guess this is the easiest approach if no one else has done the work so far...
6 replies
MModular
Created by samufi on 8/5/2024 in #questions
Is there a (N-D) contiguous data structure for non-trivial structs?
Thanks! Hmm... I do not know the size of the outer array at compile time. Is there an alternative with dynamic memory?
6 replies