sirlantis/liquid-node — Issue #2: Reevaluate `futures` as Promise implementation
Author: sirlantis
Created: 2011-12-30 20:17:42+00:00
State: open

Using `futures` works for now but we only need the `Future` class from it (and `forEachAsync` in some places). Maybe I can use a simpler Promise implementation based on EventEmitter that only does what is necessary.

NOTE: Take a look at jQuery's Deferred implementation/syntax.

Also I don't like the messy code when potential futures are wrapped and unwrapped (*unfutured*) right now:

```coffeescript

# ugly
delivered = false
result = null
f = futures.future()
doSomethingPotentialAsync ->
delivered = true
result = ...
f.deliver(...)
if delivered then result else f

# better
Promise.wrapMaybe (p) ->
doSomethingPotentialAsync ->
p.deliver(...)
```

and

```coffeescript
# okay-ish
Liquid.Helpers.unfuture potentialPromise, (err, ...) ->
...

# better
Promise.unwrap potentialPromise, (err, ...) ->
...
```