Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS Promises #552

Open
stan-kondrat opened this issue Apr 21, 2016 · 8 comments
Open

JS Promises #552

stan-kondrat opened this issue Apr 21, 2016 · 8 comments

Comments

@stan-kondrat
Copy link

V7 has support JS Promises?

@mkmik
Copy link
Collaborator

mkmik commented Apr 21, 2016

Not yet but it's being developed, stay tuned.

@ghost
Copy link

ghost commented Apr 21, 2016

Also the early async-await support would be equally awesome:
http://tc39.github.io/ecmascript-asyncawait/

@endel
Copy link

endel commented Jun 11, 2016

AFAIK v7 is single-threaded at the moment, to be able to implement promises/timeouts it would need to use some threading model, right?

@mkmik
Copy link
Collaborator

mkmik commented Jun 11, 2016

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.

@mkmik
Copy link
Collaborator

mkmik commented Jun 12, 2016

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.

@YurySolovyov
Copy link

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...

@mkmik
Copy link
Collaborator

mkmik commented Jun 19, 2016

as I said, none with plain v7 (as none would work in v8). setTimeout will work with mongoose-iot

@niwinz
Copy link

niwinz commented Jul 28, 2016

Consider using https://github.com/bluejava/zousan that is compliant, fast and very very small in comparison to other impls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants