Paul Krill
Editor at Large

Google V8 API bridges WebAssembly and asynchronous web

news
Jan 23, 20232 mins
Development Libraries and FrameworksJavaScriptWeb Development

The WebAssembly JavaScript Promise Integration API suspends a Wasm application when it issues a synchronous API call and resumes it when the asynchronous I/O operation is completed.

women spinning plates asynchronous programming synchrony multi tasking by graemenicholson getty ima
Credit: graemenicholson / Getty Images

The developers of Googleโ€™s V8 JavaScript/WebAssembly engine have introduced the JavaScript Promise Integration (JSPI) API, allowing WebAssembly applications that assume access to external functionality is synchronous to smoothly function in asynchronous environments.

Currently in an experimental stage, JSPI should not be used in production applications yet, the developers said. Eventually, it will become a standard, for implementation across major browsers, they said.

Introduced in a V8 blog post on January 19, JSPI bridges synchronous WebAssembly applications and asynchronous web APIs. This is done by suspending the application when it issues a synchronous API call and resuming when the asynchronous I/O operation is concluded. And JSPI does this with very few changes to the application itself.

Many modern APIs on the web work asynchronously by splitting functionality into the initiation and resolution of an operation. JSPI intercepts the JavaScript Promise returned from an asynchronous API call, suspending the main logic of the WebAssembly application and returning a Promise from the export used to enter the WebAssembly application. When the asynchronous API completes, the WebAssembly application is resumed so it can process results of the API call.

Working with Promises is difficult, particularly with WebAssembly, because direct manipulation of Promises in WebAssembly is not possible, the developers said. JSPI allows developers to craft WebAssembly applications using synchronous APIs and still participate in the webโ€™s asynchronous ecosystem.

JSPI is being developed on Intel and ARM64 architectures. It is available for Linux, Windows, macOS, and ChromeOS. Developers can test JSPI locally by going to chrome://flags in Chrome, searching for โ€œExperimental WebAssembly JavaScript Promise Integration (JSPI),โ€ and checking the box. Use of the Chrome Canary channel is recommended. JSPI cannot yet be enabled for end users.

WebAssembly has been hailed as a breakthrough in web application performance. The binary instruction format enables many different programming languages including C/C++, C#, and Rust to be used for web programming.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorldโ€™s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorldโ€™s audience of software developers and other information technology professionals. Paul has won a โ€œBest Technology News Coverageโ€ award from IDG.

More from this author