> > Sync require makes it hard to do things like loading code dynamically or > loading modules from a database
*Good.* On Tue, May 15, 2012 at 11:45 PM, Bruno Jouhier <[email protected]> wrote: > It's a wart in the system, and more generally, Sync calls are warts. > > Sync require makes it hard to do things like loading code dynamically or > loading modules from a database. There are workarounds. For example you can > load code from a database by caching it to local files and requiring > afterwards. And you have to accept the fact that your event loop may pause > to load code dynamically. > > The only reason why things are so is because writing async code with > callbacks is more difficult than writing sync-like code. So people take > shortcuts. > > Bruno > > > On Tuesday, May 15, 2012 5:49:57 PM UTC+2, Guoliang Cao 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 [email protected] > To unsubscribe from this group, send email to > [email protected] > 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. [email protected] -- 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en
