Promises are a tool to help write asynchronous code in a more readable style that looks more like synchronous code.
In short, promises allow you to interact with a value that may or may not be available yet.
| node_modules |
Promises are a tool to help write asynchronous code in a more readable style that looks more like synchronous code.
In short, promises allow you to interact with a value that may or may not be available yet.
This article has been given a more permanent home on my blog. Also, since it was first written, the development of the Promises/A+ specification has made the original emphasis on Promises/A seem somewhat outdated.
Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:
getTweetsFor("domenic", function (err, results) {
// the rest of your code goes here.| //------------------------------------------------------------- | |
| // | |
| // Hypothesis: | |
| // | |
| // Promises/A is a Monad | |
| // | |
| // To be a Monad, it must provide at least: | |
| // - A unit (aka return or mreturn) operation that creates a corresponding | |
| // monadic value from a non-monadic value. | |
| // - A bind operation that applies a function to a monadic value |
I'm considering adding an alternative to CanJS's EJS live-binding system. I really like EJS, it's extremely powerful, but ugly to look at. So, I'm trying to create a better mouse-trap.
Currently, the most popular mouse-trap seems to be Handlebars. What do you like about it?
Handlebars uses {{}} for insertion and {{#}} and {{/}} for widgets and control structures.
L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns
Compress 1K bytes with Zippy ............. 3,000 ns = 3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns = 20 µs
SSD random read ........................ 150,000 ns = 150 µs
Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs
Get Homebrew installed on your mac if you don't already have it
Install highlight. "brew install highlight". (This brings down Lua and Boost as well)
| #!/usr/bin/php | |
| <?php | |
| echo "\nRunning php linter...\n"; | |
| $params = explode(' ', file_get_contents('php://stdin')); | |
| $ref = trim($params[1]); | |
| $diff = array(); | |
| $return = 0; |
| // I mean, seriously, localStorage is supported even by your mum. How about instead of | |
| // casing the feature out, you give users in-memory (stale) storage instead? | |
| // If they close your application, they deserve to lose data anyway. | |
| // if (!('localStorage' in window)) { | |
| if (!Modernizr.localstorage) { | |
| window.localStorage = { | |
| _data : {}, | |
| setItem : function(id, val) { return this._data[id] = String(val); }, | |
| getItem : function(id) { return this._data.hasOwnProperty(id) ? this._data[id] : undefined; }, |
| # YUI 3 Cookbook Table of Contents | |
| ## YUI BASICS | |
| ### Put YUI on the Page | |
| * Load YUI | |
| * Load debug builds | |
| * Load locally hosted builds | |
| * Load a YUI 2 widget |