-1

Is the Javascript Promise class something one could implement fully in userspace code, without requiring any support from native code (i.e., the Javascript internals) that only someone implementing a Javascript engine (such as the V8 team) would have access to?

Note that I'm not talking about implementing a higher-level abstraction library or module around the existing Javascript Promise class (say, to make it user-friendlier); rather, I'm talking about an entirely new, replacement promise implementation, say, MyPromise, with identical semantics as Promise.

I tried reading the relevant Promise section in the ES6 spec to get my answer, but found the spec very hard to read.

Harry
  • 3,684
  • 6
  • 39
  • 48
  • 2
    Of course they can be, and have been many times. Why wouldn't they be able to be? –  Apr 06 '16 at 05:28
  • 1
    https://www.promisejs.org/implementing/ – Felix Kling Apr 06 '16 at 05:29
  • +1. Well, that's exactly what I wanted to confirm. The mutex/lock primitive in C/C++/Java, e.g., rely on support from the underlying VM/OS, so I didn't know if `Promise` too was relying on some such native support from the Javascript engine's C implementation linking ultimately to the OS. – Harry Apr 06 '16 at 05:30
  • Related: http://stackoverflow.com/questions/23772801/basic-javascript-promise-implementation-attempt/23785244#23785244 – Thilo Apr 06 '16 at 05:31
  • 2
    I'd argue that the general answer is *no*, because there doesn't seem to be a standard user facing API to add something to the job queue. However, most environments implement `setTimeout` with which this is possible. – Felix Kling Apr 06 '16 at 05:32

1 Answers1

2

Is the JavaScript Promise class something one could implement fully in userspace code, without requiring any support from native code?

Yes.

The prime example is Bluebird.