cujojs / when

A solid, fast Promises/A+ and when() implementation, plus other async goodies.
Other
3.44k stars 396 forks source link

Passing arguments into resolver when calling when.promise(r) #445

Open markbjerke opened 9 years ago

markbjerke commented 9 years ago

I want when.lift(f) but that returns a (thenable) object with an execute method. The object could even be an extension of a Promise, for maximum leverage but it's not important overall.

Something like: p(r) = when.task( r ); p.execute(....), p.then(...) where p(r) is a theable with a way to execute r(args); e.g. p.execute(args), on demand.

I was thinking of writing a factory method and extending when.Promise, since a function amplified with a record is a (future) unit of work that can be, named, composed etc..

With when.lift(f) , you get back a promisified fn. Even though I can merge properties on a function it seems awkward although with javascript that is more the perception then the reality perhaps :+1:

g = when.lift(f) t = _.merge(g, {config}); g( args ); g as record;

if we had a flavor of when.lift, that returned an object with an execute method, it would be more reasonable to think of a lifted function as a deferred resolver as a record that has a an execute method. There is a writer monad in Haskell for instance that is similiar.

Is there room for this idea in a Promise library, and is there anything to gain from making the above ideas standardized ?

thanks mark bjerke

briancavalier commented 9 years ago

Hey @markbjerke, I'm trying to get my head around this :) Can you help me out with a more complete code example of what you mean? Thanks!

briancavalier commented 9 years ago

Ping @markbjerke. I'm still trying to understand what you mean here. Can you add a more complete example?