Promises, async and await
Opened this issue · 0 comments
kaleidawave commented
Currently Promise
type annotations and await
ing them does work. But that is it
One thing currently stuck on is how to represent the flow in a async situation
async function func(something: Promise<T>) -> Promise<[T]> {
const x = await new Promise((res, rej) => res(2));
// this returns when `res` is called
await new Promise((res, rej) => setTimeout(res, 1000));
// this runs when setTimeout calls res
const y = await something;
return [y]
}
let x = 0;
async function immediate() {
x = 1
}
x satisfies 0;
immediate(); // (btw await has no effect here, unlike Rust)
x satisfies 1
/// On the other hand
let x = 0;
const wait = new Promise((res, rej) => {
setTimeout(res, 1000);
}).then((_) => {
x = 1;
});
x satisfies 0;
await wait; // Does have an effect. If not `await`, then the next == 0
x satisfies 1;
Thinking
- What happens in
Event::Await
???- Could there be
Event::WaitsToFunctionToBeCalled
???
- Could there be
- How to represent non-immediate function calls
- This partially exists via
CallingTiming
- Getters need to be called under functions that are not
FunctionEffect::SideEffects
(separate issue and not currently implemented) - Maybe more information sent in decorators
- This partially exists via
- What happens for conditional
await
branches- This seems really difficult for unknown-ness. Trailing events need to be run somewhat synchronously and non-synchronously
- ...
Additionally
- Calling
then
-ables async
functions returns should return aPromise<...>
- Checking whether
await
is valid in some place- Warn if
await
has no effect
- Warn if