slightlyoff / Promises

DOM Promises IDL/polyfill
Apache License 2.0
154 stars 28 forks source link

Resolver API should hide resolve() #55

Closed cowwoc closed 11 years ago

cowwoc commented 11 years ago

I'd like to propose the following design change:

Invoking accept from a Resolver invokes a hidden method resolve if there are any chained Resolvers, otherwise it invokes another hidden method finalAccept.

This way users would only have to be aware of accept and reject. Currently we require users to invoke resolve which I found to be very confusing. I shouldn't have to invoke different methods depending on whether chaining is taking place or not; that should be an implementation design.

slightlyoff commented 11 years ago

The semantics of accept and resolve are different, and accept is the lower-level variant. It sounds like your suggestion is to give accept (now fulfill) the resolve semantics and move the accept semantics to finalAccept?

I'm not sure what that buys us. There is active disagreement about weather or not programmers should use accept or resolve, and removing one or the other is hostile to at least one camp.

cowwoc commented 11 years ago

@slightlyoff,

When would a user ever need to invoke fulfill directly? Shouldn't users always invoke resolve?

neonstalwart commented 11 years ago

@cowwoc the semantics are different - resolve will unwrap/resolve promises passed as the value whereas fulfill just blindly takes the value it's given and passes it along.

  // Directly resolves the Promise with the passed value
  void fulfill(optional any value);

  // Indirectly resolves the Promise, chaining any passed Promise's resolution
  void resolve(optional any value);
cowwoc commented 11 years ago

So you're saying fulfill() causes the promise to override any values returned by subsequent chains? Why/when when you want to do that?

neonstalwart commented 11 years ago

Why/when when you want to do that?

see #53 (and i think #26 as well and maybe another or maybe it was in various other places) - a lot of ground has already been covered in those tickets.