The reason require() is synchronous is because asynchronous require() is quite burdensome to work with and the majority of require() calls happen on start up, where blocking I/O isn't a concern. In the early days, there was require.async() but it was a pain for node devs and node users. See https://github.com/joyent/node/commit/bb08f0c219bf4ca99b1129f54ef415ce46b01f22
On Tue, May 15, 2012 at 2:30 PM, Martín Ciparelli <mcipare...@gmail.com>wrote: > So the question would be: why an async-driven platform uses sync-driven > way to load modules? > > > 2012/5/15 Marak Squires <marak.squi...@gmail.com> > >> require() is a sync call. >> >> If you need an async require ( a require that performs i/o ), you should >> check out a plugin system like Broadway ( >> https://github.com/flatiron/broadway ) >> >> This will allow you to require modules with an optional .init and .attach >> methods, which can both accept optional callbacks. >> >> >> On Tue, May 15, 2012 at 8:49 AM, Guoliang Cao <gca...@gmail.com> wrote: >> >>> Hi, >>> >>> I'm new to Node.js and wrapping my head around the asynchronous >>> programming model. A question comes to mind is why 'require' itself does >>> not use callbacks like below. I believe IO is involved in require and a lot >>> of things can fail. >>> >>> require('http', >>> function(http){ >>> // do stuff with http >>> }, >>> function(error) { >>> console.log("Failed to load http"); >>> }); >>> >>> >>> Thanks, >>> Guoliang Cao >>> >>> -- >>> Job Board: http://jobs.nodejs.org/ >>> Posting guidelines: >>> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines >>> You received this message because you are subscribed to the Google >>> Groups "nodejs" group. >>> To post to this group, send email to nodejs@googlegroups.com >>> To unsubscribe from this group, send email to >>> nodejs+unsubscr...@googlegroups.com >>> For more options, visit this group at >>> http://groups.google.com/group/nodejs?hl=en?hl=en >>> >> >> >> >> -- >> -- >> Marak Squires >> Co-founder and Chief Evangelist >> Nodejitsu, Inc. >> marak.squi...@gmail.com >> >> -- >> Job Board: http://jobs.nodejs.org/ >> Posting guidelines: >> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines >> You received this message because you are subscribed to the Google >> Groups "nodejs" group. >> To post to this group, send email to nodejs@googlegroups.com >> To unsubscribe from this group, send email to >> nodejs+unsubscr...@googlegroups.com >> For more options, visit this group at >> http://groups.google.com/group/nodejs?hl=en?hl=en >> > > -- > Job Board: http://jobs.nodejs.org/ > Posting guidelines: > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines > You received this message because you are subscribed to the Google > Groups "nodejs" group. > To post to this group, send email to nodejs@googlegroups.com > To unsubscribe from this group, send email to > nodejs+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/nodejs?hl=en?hl=en > -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to nodejs@googlegroups.com To unsubscribe from this group, send email to nodejs+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en