Skip to content

Add "init" lifecycle hook #7779

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

Open
wants to merge 2 commits into
base: dev-2.0
Choose a base branch
from

Conversation

quinton-ashley
Copy link
Contributor

@quinton-ashley quinton-ashley commented Apr 25, 2025

Added two lines of code that implement the "init" lifecycle hook in p5 v2.

This is needed for preload system compatibility. Issue #7742 can't be fixed by moving the current "presetup" hook.

Added two lines of code that implement the "init" lifecycle hook in p5 v2.

This is needed for preload compatibility.
@davepagurek
Copy link
Contributor

Hey @quinton-ashley, thanks for making a PR! I think because we aren't awaiting the hooks, there are some bugs currently. Since we currently await every lifecycle hook, if there exists more than one addon using init, it looks like only the first one gets run before globals are initialized: https://editor.p5js.org/davepagurek/sketches/zZy1xer18

Arguably we shouldn't be awaiting non-async hooks though -- see some discussion here: #7770 (comment) If we end up implementing that, then this implementation will work as-is though (assuming init hooks are never async, which I think is reasonable if this is intended only to be used to initialize globals.)

@quinton-ashley
Copy link
Contributor Author

quinton-ashley commented Apr 27, 2025

@davepagurek ah yes you're right

assuming init hooks are never async, which I think is reasonable if this is intended only to be used to initialize globals.

Yes and for now I'll edit the PR based on that assumption.

@quinton-ashley
Copy link
Contributor Author

I think this PR works as a fix for #7742 now.

I'd like if it could be merged before other lifecycle changes are finalized, as that could take a while.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants