Skip to main content

News

Topic: minipact 1.1b4 (Read 1070 times) previous topic - next topic

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • miniSphere Developer
minipact 1.1b4
So what started as a strict polyfill for ES6 Promise became this:

[gist=422d45812b6f402360d9][/gist]

See, as defined by spec, a Promise can only be fulfilled or rejected by the code inside of it.  This makes them very difficult to use for their intended purpose of asynchronous fulfillment.  Basically you end up having to juggle two things for every single promise--the promise itself, and the callback it registers with to resolve itself.  How did I fix it?  By extending the metaphor, of course!  Now instead of just Promises...

Code: (javascript) [Select]
var pact = new mini.Pact();
var promise = pact.makePromise();
// now you give out the promise, and then later on...
pact.resolve(promise, value);


You also have Pacts!  A given Pact can only resolve promises made from it, so you can't pull dirty tricks of making up a pact to fulfill promises on others' behalf--or if you were feeling particularly nasty, rejecting them(!). That would be VERY VERY bad! :P  Attempting to do so will throw a TypeError.
  • Last Edit: May 10, 2015, 11:40:09 pm by Lord English
miniSphere 5.0.1 - Cell compiler - SSj debugger - thread | on GitHub
For the sake of our continued health I very much hope that Fat Cerberus does not become skilled enough at whatever arcane art it would require to cause computers to spawn enourmous man eating pigs ~Rhuan