javascript - Why do JS Promise A+ create/fulfill/reject not part of the spec? -


http://promisesaplus.com/

finally, core promises/a+ specification not deal how create, fulfill, or reject promises, choosing instead focus on providing interoperable method. future work in companion specifications may touch on these subjects.

as functional developer, deal monads , operators point bind map or flatmap chain calls wrapped inside monad box.

according question js deferred/promise/future compared functional languages scala, map , flatmap operators seems melted under then in js spec, because not make sense provide both in dynamically typed language js (?) , more convenient use , remember single operator.


so far good, there's then operator (that doesn't seem implemented)

but why promise create / fulfill / reject not part of spec? it's having half monad :( it seems i'm not 1 complain

typically, problem is:

  • i want create js library
  • i want expose promise-based api
  • i want client choose promise implementation wants use

now supposed do?

i can create promises in library like

q.fcall(function () {     return 10; }) 

ok cool, coupled library q :(

so, there solution problem? how library author supposed create promises exposes api without coupling implementation?

is there license-free minimum viable promise a+ library can embed in our libraries or something?

what reasons behind spec choice?

what reasons behind spec choice?

as ben points out in comments, idea of promises/a+ specification not provide sort of library api. it's provide minimum interoperable set of primitives consumes promise can depend on having uniform interface. important cross-library interop e.g. @ seams of different components of application, different promise libraries may in use internally. specifying full api promise library isn't necessary meet goal.

is there license-free minimum viable promise a+ library can embed in our libraries or something?

there many promises/a+ implementations. don't think of them license-free, thing, because they'd default rights reserved authors. (all?) of them open-source licensed, though, should fine.

how library author supposed create promises exposes api without coupling implementation?

i literally not understand how possible. if rephrase question, asking, "how create promise, without using promise implementation?" that's plain not possible.

  • i want expose promise-based api
  • i want client choose promise implementation wants use

this goal, on other hand, different story. if want allow people choose promise implementations, there couple easy options.

first, return promise of implementation; consumer can convert preferred 1 using library's coercion methods. e.g. if library returns when promise , i, consumer, want q promise, can q(yourlibrary.getpromise()).

alternately, allow library follows promises/a+ constructor proto-spec. largely de-facto standard now; major libraries, including promises built es6, follow specification. example allow users yourlibrary.promise = q.promise, , inside library use assigned promise constructor create promises.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -