-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/YoavSarfaty/Multithread
- Loading branch information
Showing
1 changed file
with
20 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,21 @@ | ||
# Multithread | ||
Multithreading in js | ||
Multithread is a little JavaScript library that helps you use multiple threads in the browser. | ||
It uses webworkers but supports nested threads (I don't know any browser that supports nested webworkers), and it has a dead simple api. | ||
|
||
say you have a function `myFunction`, and you would like it to run in a background thread, all you need to do is use the global `multithread` function to create a new thread: | ||
|
||
```javascript | ||
multithread(myFunction)(myArg) | ||
``` | ||
This will return a Promise that will be resolved once `myFunction` returns a value in the background thread, so you can use is with async/await (`myFunction` doesn't have to be a async function). | ||
|
||
But what if `myFunction` calls some other function `otherFunction`? you can give multithread an array of all function you may call so they will be written to the webworker: | ||
|
||
```javascript | ||
multithread(myFunction, [otherFunction])(myArg) | ||
``` | ||
|
||
That's it, it's as simple as that! | ||
|
||
## Performance | ||
You can measure the performance [in this merge sort test.](https://yoavsarfaty.github.io/Multithread/) |