Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Got Milk? A short introduction to node.js and e...

Got Milk? A short introduction to node.js and event-driven programming.

A short introduction to node.js and event-driven programming.

Alexey Taktarov

May 07, 2012
Tweet

More Decks by Alexey Taktarov

Other Decks in Programming

Transcript

  1. milk = dear_son.please_buy_a_milk(); /* Event loop starts - while(…) */

    if( dear_son.milk_ready() ) break; do_some_cleanup(); /* Event loop ends */ Event-Loop
  2. In terms of: 1. OS ( process, threads scheduling) 2.

    Application ( event-loops, overlapped system calls, callbacks )
  3. OS can handle it. So why should I know about

    event-loops and other sh!t?!
  4. Why Javascript? 1. It’s awesome 2. It’s simple 3. It’s

    popular 4. V8 is really fast 5. Built-in support for callbacks, lambdas, closures and other magic
  5. Dummy example #2 var http = require(‘http’); http.createServer(function (req, res)

    { res.writeHead(200, {'Content-Type': ‘text/plain'}); res.end('Hello World\n'); }).listen(1337, '127.0.0.1'); console.log('Server running at port 1337');
  6. Features 1. Clustering 2. Packages: web-frameworks, DB, graphics, BNF parsers,

    unit- testing, … + package manager 3. Cloud 9 IDE (runs in browser)
  7. Problems Asynchronous logic hell! 1. Using helper modules (deferred, async,

    node-fibers) 2. Program is Finite State Machine
  8. Resources 1. “UNIX internals” by U.Vahalia 2. “Thinking Asynchronous in

    C++” by author of boost::asio http://blog.think-async.com/ 3. Online npm repository http://search.npm.js 4. Cloud 9 IDE http://c9.io