JS Promises
V7 has support JS Promises?
Not yet but it's being developed, stay tuned.
Also the early async-await support would be equally awesome: http://tc39.github.io/ecmascript-asyncawait/
AFAIK v7 is single-threaded at the moment, to be able to implement promises/timeouts it would need to use some threading model, right?
no. promises have nothing to do with threading. there are pure js implementations of promises you can use . we intend to include an implementation as part of the v7 standard library. we want to make it small enough so it can work well on embedded platforms.
for the record, pure JS promises usually require a way to postpone invocation to the next event loop iteration (i.e. setTimeout, setImmediate, process.nextTick()). V7 is just a JS interpreter and doesn't have a concept of event loop.
We do implement event loop and setTimeout for several platforms in https://github.com/cesanta/mongoose-iot.
As an analogy, V7 is for mongoose-iot, as V8 is for node.js. A relevant thread on StackOverflow:
http://stackoverflow.com/questions/12335222/settimeout-and-v8
setTimeout is not part of ECMA-262, it's implemented by the browsers. However, if you install Node.js (which is V8 + extras) you will get a command line setTimeout.
That said, just for the craic, I tried out https://github.com/stefanpenner/es6-promise, one of the many promise polyfills (minified with uglifyjs --compress --mangle -- es6-promise.js since they seem to no longer distribute the minified version themselves), and it seems to work just fine with V7.
That impl is about 6k in size and is not optimized for embedded, which is why we're working on making it smaller.
this promise polyfill tries several postponing methods:
if (isNode) {
scheduleFlush = useNextTick();
} else if (BrowserMutationObserver) {
scheduleFlush = useMutationObserver();
} else if (isWorker) {
scheduleFlush = useMessageChannel();
} else if (browserWindow === undefined && typeof require === 'function') {
scheduleFlush = attemptVertx();
} else {
scheduleFlush = useSetTimeout();
}
I wonder which one succeeds...
as I said, none with plain v7 (as none would work in v8). setTimeout will work with mongoose-iot
Consider using https://github.com/bluejava/zousan that is compliant, fast and very very small in comparison to other impls.