https://github.com/hand-dot/wkn
wkn makes it easy for other threads to execute processing🚀 Check Demo👉 https://jsfiddle.net/hand_dot/qjcrk6hs/30/
https://github.com/hand-dot/wkn
multithreading thread webworker woker
Last synced: 11 months ago
JSON representation
wkn makes it easy for other threads to execute processing🚀 Check Demo👉 https://jsfiddle.net/hand_dot/qjcrk6hs/30/
- Host: GitHub
- URL: https://github.com/hand-dot/wkn
- Owner: hand-dot
- License: mit
- Created: 2018-09-01T11:27:29.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-12-25T14:53:06.000Z (over 7 years ago)
- Last Synced: 2025-06-03T16:19:05.593Z (about 1 year ago)
- Topics: multithreading, thread, webworker, woker
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/wkn
- Size: 639 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/hand-dot/wkn)

wkn is easy possible to run the processing to another thread.
# Concept
* Simple API
* No Config
* Light
# Installing
```bash
$ npm install wkn
```
# Example
```javascript
import wkn from 'wkn';
/**
* Takes function and arguments, moves the processing to another thread,
* and receives the processing result on Promise.
* @param {Function} function to have retunrn value. (Be processed in Web Worker context)
* @param {...*} [arguments] arguments
* @returns {Promise} Returns Processing result as Promise
*/
// Simple usage
wkn(arg => arg + 1, 100)
.then((value) => {
console.log(value); // 101
});
// Two arguments
wkn((arg1, arg2) => `${arg1}!${arg2}!`, 'hoge', 'foo')
.then((value) => {
console.log(value); // hoge!foo!
});
// Use moment.js
wkn((years, months, days, hours, minutes, seconds) => {
importScripts('https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.js');
const m = moment(new Date(years, months, days, hours, minutes, seconds));
return m.hours();
}, 2011, 2, 12, 5, 0, 0)
.then((value) => {
console.log(value); // 5
});
// Heavy processing
wkn(() => {
let num = 0;
for (let i = 0; i < 100000000; i++) {
num += i;
}
return num;
})
.then((value) => {
console.log(value); // 4999999950000000
});
// onRejected
wkn(arg => arg.map(_ => `${_}!`), {})
.then((value) => {
console.log(value); // not fire
}, (reason) => {
console.error(reason); // arg.map is not a functio
});
```