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

Turn dependenciesFulfilled into an array #13220

Closed
wants to merge 6 commits into from

Conversation

dalcde
Copy link
Contributor

@dalcde dalcde commented Jan 9, 2021

This function returns a promise that resolves when all run dependencies are fulfilled. I use this to wait for file_packager bundles to load.

I can add documentation and tests if this feature is accepted.

This function returns a promise that resolves when all run dependencies
are fulfilled.
src/preamble.js Outdated Show resolved Hide resolved
dalcde added 2 commits January 9, 2021 23:55
This replaces the previous dependenciesFulfilled. Rename to
onDependenciesFulfilled
Simply adding to onDependenciesFulfilled would suffice
@dalcde dalcde changed the title Add waitRunDependencies Turn dependenciesFulfilled into an array Jan 9, 2021
@dalcde
Copy link
Contributor Author

dalcde commented Jan 9, 2021

I've decided for my purposes, it suffices to turn dependenciesFulfilled to an array; the user can simply expose it and append to it themselves. I have renamed it to onDependenciesFulfilled to be more descriptive.

@sbc100
Copy link
Collaborator

sbc100 commented Jan 9, 2021

What exactly are you trying to achieve? Is there some reason why the current hooks for you:

var __ATPRERUN__  = []; // functions called before the runtime is initialized                 
var __ATINIT__    = []; // functions called during startup                       
var __ATMAIN__    = []; // functions called when main() is to be run             
var __ATEXIT__    = []; // functions called during shutdown                      
var __ATPOSTRUN__ = []; // functions called after the main() is called  

If you want you code to run after all the file packages have been loaded I think __ATMAIN__ might be what you want. You can use addOnPreRun to add something to this array.

@dalcde
Copy link
Contributor Author

dalcde commented Jan 9, 2021 via email

@sbc100
Copy link
Collaborator

sbc100 commented Jan 10, 2021

What exactly are you trying to achieve?
I load new files after main has run.

Then don't you want to put your callback in __ATPOSTRUN__.

Doing things during onDependenciesFulfilled happens before main, right?

@dalcde
Copy link
Contributor Author

dalcde commented Jan 10, 2021 via email

@sbc100
Copy link
Collaborator

sbc100 commented Jan 10, 2021

I meant that during runtime, users can perform actions to trigger loading new files, and I want to know when those files are loaded.

Hmm.. I'm not sure this is the best approach "dependencies fulfilled" means "are the the dependencies of them main application fulfulled and can we now run main." If main is already running then by definition the dependencies are fulfilled. Perhaps its just a questions of renaming / refactoring but the dependencies here are for more than just files, they are for all kind of things. Its sounds like you want some kind of promise that resolves when files are asynchronously loaded at runtime?

@dalcde
Copy link
Contributor Author

dalcde commented Jan 10, 2021 via email

@kripken
Copy link
Member

kripken commented Jan 12, 2021

A downside to generalizing the mechanism as in this PR is that it increases code size.

Can you wrap the existing callback? That is, if dependenciesFulfilled is a function (and not null), make a new function with your new code, and that also calls the old one.

@dalcde
Copy link
Contributor Author

dalcde commented Jan 12, 2021 via email

Base automatically changed from master to main March 8, 2021 23:49
@stale
Copy link

stale bot commented Apr 16, 2022

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant.

@stale stale bot added the wontfix label Apr 16, 2022
@dalcde dalcde closed this Apr 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants