This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
non-blocking require() #282
Comments
There is require.async there. |
And for CommonJS, there's |
@Herby: is it in master? or are you referring to isaacs fork? Any doc somewhere? EDIT: found it in src/node.js: 'require.async = requireAsync;' where signature is require.async( string url, function cb( Error|null err, undefined|object exports) ); |
Simple proof of concept extending require.async to support array: |
Did the API change? In 0.4.5, both require.async or require.ensure are both undefined. |
yes, removed in 0.3 |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Couldn't find this anywhere so creating a issue for it.
As mentioned by Douglas Crockford in a recent YUI Theater post: Loopage 38:30 - 39:42, require() should be non blocking.
I have tried to suggest a syntax beneath with performance in mind. Other then that; object types, function names and param names are just suggestions and is up for debate.
Possible syntax:
Example use:
In the first round something like the code / syntax shown above (note: in the end there should only be one require function, and it should be non-blocking imho. Just calling it require2 for convenience).
(optional) It should use the same require.paths system as require, with one distinct difference, it should lookup list of modules and cache on first call to not have to iterate the list on each call. This cache should be cleared on changes to .paths, something that might imply that it should use functions to add / remove instead of exposing it as writeable, or to not break the syntax, enforce usage of a require2.clearCache() or similar.
This cache should probably be disabled in debug mode (as mentioned in node.js's TODO)
2.1 (possibility) require.paths could be read in reverse order to allow an 'override' system where you can override modules to extend them to your needs, but such a feature should probably be disabled by default and enabled with a 'settings' param, e.g.: { 'reverse_paths': true }
For later probably, but should be mentioned: module dependency support
This will be needed when require stops being synchronous, and should hence be handled by the loader.
We don't have oversight like YUI has for use(), and neither do we want to hard code dependencies in our user code for external modules we use, when the module can be updated at any time and at some point people will probably use so many it would just be ridiculous to have to maintain a hash of dependencies your self. So modules should define this them self but in a way so that the loader can know about it before it loads and executes the module (so not like YUI.add does).
Could reuse package.json for this or something similar, at least a extend able json format, and let cache mentioned in 2. handle loading this for all modules on first use.
Notes:
The text was updated successfully, but these errors were encountered: