Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

add ES6 example #277

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ npm install napajs
Other options can be found in [Build Napa.js](https:/Microsoft/napajs/wiki/build-napa.js).

## Quick Start
### Using ES5
```js
const napa = require('napajs');
const zone1 = napa.zone.create('zone1', { workers: 4 });
Expand All @@ -29,6 +30,24 @@ zone1.execute(
console.log(result.value);
});
```

### Using ES6 + async/await
```js
import * as napa from "napajs"

const zone1 = napa.zone.create('zone1', { workers: 4 });

// Broadcast code to all 4 workers in 'zone1'.
zone1.broadcast('console.log("hello world");');

// Execute an anonymous function in any worker thread in 'zone1'.
(async () => {
let result = await zone1.execute(
(text) => text,
['hello napa']);
console.log(result.value);
})()
```
More examples:
* [Estimate PI in parallel](./examples/tutorial/estimate-pi-in-parallel)
* [Max sub-matrix of 1s with layered parallelism](./examples/tutorial/max-square-sub-matrix)
Expand Down