Asynchronous data access

As a natural consequence of the heavy computation of machine learning algorithms, asynchronous data access is inevitable if we wish to keep our application efficient and working interactively. In JavaScript, asynchronous execution is often implemented with a Promise object. A promise represents an asynchronous operation that ends in either success or failure. Most of the operations that download data from tensors return a Promise object, which ensures that the user fetches the data once it is ready.

To return a Promise object, we need to declare the function as an async. For instance, the Tensor.data method returns a Promise that computes TypedArray, which contains the data's results:

async data<D extends DataType ...

Get Hands-On Machine Learning with TensorFlow.js now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.