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
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:
-
Create Array
-
Connect to DB
-
Fill Array
-
Return Array
Get:
-
Create Array
-
Connect to DB
-
Jeez, this looks like it'll take a while
-
Return Array
-
Fill Array
So, is there a solution?
There is.
I promise.
nextworld.js
node.js
http
MongoDB
q
Run the code
Promises, Promises
-
Make a promise
-
Create array
-
Connect to DB
-
Return promise
-
Fill array
-
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