Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promises, async and await #168

Open
kaleidawave opened this issue Jun 20, 2024 · 0 comments
Open

Promises, async and await #168

kaleidawave opened this issue Jun 20, 2024 · 0 comments
Assignees
Labels
blocking These issues are blocking the checker being used in projects checking Issues around checking needs-investigation Further information is requested

Comments

@kaleidawave
Copy link
Owner

Currently Promise type annotations and awaiting 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 ???
  • 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
  • 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 a Promise<...>
  • Checking whether await is valid in some place
    • Warn if await has no effect
@kaleidawave kaleidawave added needs-investigation Further information is requested checking Issues around checking labels Jun 20, 2024
@kaleidawave kaleidawave self-assigned this Jun 20, 2024
@kaleidawave kaleidawave added the blocking These issues are blocking the checker being used in projects label Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocking These issues are blocking the checker being used in projects checking Issues around checking needs-investigation Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant