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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow web frame methods to return async promises #7533

Merged
merged 5 commits into from Nov 3, 2016

Conversation

Projects
None yet
3 participants
@MarshallOfSound
Member

MarshallOfSound commented Oct 9, 2016

Fixes #7532

Basically this handles executeJavaScript calls returning instances of Promise and resolving that promise before passing it back through IPC to the caller.

This trick works because

Promise.resolve(123).then((resolvedValue) => console.log(resolvedValue))
// This would print out 123
// Promise.resolve either immediately resolves with the given value or resolves the given promise

It allows for truly asyncronous execution like so

webContents.executeJavaScript(
  `new Promise(resolve => {
    setTimeout(() => resolve('myString'), 2000);
  });`,
  (returnValue) => {
     // returnValue === 'myString'
  }
);

This is non-blocking async execution 馃憤

@kevinsawicki

This comment has been minimized.

Show comment
Hide comment
@kevinsawicki

kevinsawicki Oct 10, 2016

Contributor

Would be great to get some spec coverage for this case.

Contributor

kevinsawicki commented Oct 10, 2016

Would be great to get some spec coverage for this case.

@MarshallOfSound

This comment has been minimized.

Show comment
Hide comment
@MarshallOfSound

MarshallOfSound Oct 10, 2016

Member

@kevinsawicki Added an async spec 馃憤

Member

MarshallOfSound commented Oct 10, 2016

@kevinsawicki Added an async spec 馃憤

Show outdated Hide outdated docs/api/web-contents.md
Show outdated Hide outdated spec/api-browser-window-spec.js
Show outdated Hide outdated lib/browser/api/web-contents.js

@kevinsawicki kevinsawicki self-assigned this Oct 12, 2016

@MarshallOfSound

This comment has been minimized.

Show comment
Hide comment
@MarshallOfSound

MarshallOfSound Oct 24, 2016

Member

@kevinsawicki Just realized I hadn't updated this 馃槅

I think I addressed your comments 馃憤

Member

MarshallOfSound commented Oct 24, 2016

@kevinsawicki Just realized I hadn't updated this 馃槅

I think I addressed your comments 馃憤

@kevinsawicki

This comment has been minimized.

Show comment
Hide comment
@kevinsawicki

kevinsawicki Nov 3, 2016

Contributor

Thanks for this @MarshallOfSound 馃憤

Contributor

kevinsawicki commented Nov 3, 2016

Thanks for this @MarshallOfSound 馃憤

@kevinsawicki kevinsawicki merged commit 7e90bb4 into master Nov 3, 2016

8 of 9 checks passed

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
electron-linux-arm Build #4602415 succeeded in 66s
Details
electron-linux-ia32 Build #4602416 succeeded in 60s
Details
electron-linux-x64 Build #4602417 succeeded in 121s
Details
electron-mas-x64 Build #2735 succeeded in 8 min 51 sec
Details
electron-osx-x64 Build #2749 succeeded in 8 min 48 sec
Details
electron-win-ia32 Build #1813 succeeded in 7 min 32 sec
Details
electron-win-x64 Build #1787 succeeded in 7 min 39 sec
Details

@kevinsawicki kevinsawicki deleted the async-executeJavaScript branch Nov 3, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment