Open
Description
Describe the problem
There have been several discussions about the issues of runes and async
, for example, #13916. Many apps depend on async code, and it can become difficult to migrate to Svelte 5 because of this.
Describe the proposed solution
It would be useful to have two asynchronous runes: $effect.async
and $derived.async
. These functions would be asynchronous counterparts to $effect
and $derived.by
, respectively. Here's an example:
let fetched = $derived.async(async()=>{
let res = await fetch('./example.json');
return await res.json();
});
$effect.async(async () =>{
let asyncValue = await getAsyncValue();
if(asyncValue === preferredAsyncValue) {
runCallback();
}
});
You may notice that these functions do not require await
to be called to use them, this would be because the await
would be inserted at compile time:
let thing = $derived.async(asyncValue);
$inspect(thing);
//turns into
let thing = await $.derived_async(asyncValue);
$.inspect_async(async() =>[await $.get_async(thing)]);
Importance
would make my life easier