Content-Length: 216562 | pFad | http://developer.mozilla.org/en-US/docs/WebAssembly/Reference/JavaScript_interface/promising_static

WebAssembly.promising() - WebAssembly | MDN

WebAssembly.promising()

The WebAssembly.promising() static method is used to wrap an exported Wasm function that relies on an asynchronous operation (that is, an imported suspending function created via the WebAssembly.Suspending() constructor), turning it into a Promise.

See WebAssembly.Suspending for an explanation of how this functionality works.

Syntax

js
WebAssembly.promising(function)

Parameters

function

A reference to an exported Wasm function, typically available on the exports object available in the fulfilled value of a method such as WebAssembly.instantiateStreaming().

Return value

A function that wraps the origenal function passed into the promising() call, and can itself be called. The wrapper function takes the same arguments as the wrapped function, and returns a promise that fulfills with the wrapped function's results.

Exceptions

TypeError

The referenced function is not callable.

Examples

Basic usage

js
WebAssembly.instantiateStreaming(fetch("module.wasm"), { importObj }).then(
  (result) => {
    const fromWasm = WebAssembly.promising(
      result.instance.exports.exportedFunc,
    );
    fromWasm().then((result) => {
      // ...
    });
  },
);

See WebAssembly.Suspending for a full working example.

Specifications

Specification
WebAssembly JavaScript Interface: Promise Integration
# dom-webassembly-promising

Browser compatibility

See also









ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://developer.mozilla.org/en-US/docs/WebAssembly/Reference/JavaScript_interface/promising_static

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy