Never Is A Promise

Dave Jacoby
Purdue Perl (*cough*) Mongers
April 2014

A Quick Word on NoSQL

Three types:
  • Key/Value (Cassandra, Redis)
  • Document Store (MongoDB)
  • Graph (I don't get this at all, forget I said anything)


You can fake Key/Value into Document Store
by storing as stringified JSON 

You can fake Document Store into Key/Value 
by using very shallow documents

We touch MongoDB in this presentation

world.js

node.js
http
MongoDB

Run the code

Javascript Doesn't Block!

Expect:
  1. Create Array
  2. Connect to DB
  3. Fill Array
  4. Return Array

Get:
  1. Create Array
  2. Connect to DB
  3. Jeez, this looks like it'll take a while
  4. Return Array
  5. Fill Array

So, is there a solution?

There is.

I promise.

nextworld.js

node.js
http
MongoDB
q

Run the code

Promises, Promises


  1. Make a promise
  2. Create array
  3. Connect to DB
  4. Return promise
  5. Fill array
  6. Fulfill promise with array

    I believed your promises and lies

                      promiseReturningFunction()
                            .then(
                                  function ( result ) {
                                        /* handle successful result */
                                        } ,
                                  function ( excuse ) {
                                        /* curse your sudden but inevitable betrayal*/
                                        
                                  ) ;

    But Wait! Isn't this a PERL Group?

    use Promises qw( collect deferred ) ;

    Run the code

    Thank You

    Further Reading:
    http://en.wikipedia.org/wiki/Futures_and_promises
    https://github.com/kriskowal/q
    http://documentup.com/kriskowal/q/
    http://search.cpan.org/dist/Promises

    Find Me:
    jacoby (at) purdue.edu
    Twitter: @jacobydave
    Google+: +DaveJacoby
    LinkedIn: JacobyDavid

    Never Is A Promise

    By Dave Jacoby

    Never Is A Promise

    • 823