e01.org

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.

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()`](/docs/WebAssembly/Reference/JavaScript_interface/Suspending/Suspending) constructor), turning it into a Promise.

See [`WebAssembly.Suspending`](/docs/WebAssembly/Reference/JavaScript_interface/Suspending) for an explanation of how this functionality works.

## Syntax

```js-nolint
WebAssembly.promising(function)
```

### Parameters

- `function`
- : A reference to an exported Wasm function, typically available on the [`exports`](/docs/WebAssembly/Reference/JavaScript_interface/Instance/exports) object available in the fulfilled value of a method such as [`WebAssembly.instantiateStreaming()`](/docs/WebAssembly/Reference/JavaScript_interface/instantiateStreaming_static).

### Return value

A function that wraps the original 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`](/docs/WebAssembly/Reference/JavaScript_interface/Suspending) for a full working example.

## Specifications

## Browser compatibility

## See also

- [`WebAssembly.Suspending`](/docs/WebAssembly/Reference/JavaScript_interface/Suspending)
- [`WebAssembly.Suspending()`](/docs/WebAssembly/Reference/JavaScript_interface/Suspending/Suspending) constructor
- [WebAssembly](/docs/WebAssembly) overview

source: MDN Web Docs mirror · page

Cite this

"WebAssembly.promising()". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/WebAssembly/Reference/JavaScript_interface/promising_static

JSON record · API collection · citation policy