Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iainmon/thread.js
Javascript Async the way I like it. The first library I made.
https://github.com/iainmon/thread.js
asynchronous-statements javascript javascript-async thread
Last synced: 6 days ago
JSON representation
Javascript Async the way I like it. The first library I made.
- Host: GitHub
- URL: https://github.com/iainmon/thread.js
- Owner: Iainmon
- License: mit
- Created: 2018-10-31T21:37:09.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2018-11-28T04:51:45.000Z (about 6 years ago)
- Last Synced: 2024-12-09T23:43:54.905Z (about 1 month ago)
- Topics: asynchronous-statements, javascript, javascript-async, thread
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/async-threading
- Size: 7.81 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Thread.js
=========Javascript async the way I like it.
## Installation
`npm install async-threading`## Usage
```javascript
let Thread = require('async-threading');
```
### - TasksSame scope as block:
```javascript
let callEverySecond = new Thread( () => {
console.log(callEverySecond.fireTimes + ' seconds have passed.');
}, 1000);
```
Anonymous scope:
```javascript
let callEverySecond = new Thread( function () {
console.log(this.fireTimes + ' seconds have passed.');
}, 1000);
```
* Methods for task Threads
* `.toggle()` Sets the Thread to the opposite state.
* `.kill()` Stops and sets the Thread to `undefined`.
These will be called ever `1000ms` (one second).
- Warning: I do not recomend doing `new Thread` without assigning it to a variable, because you will not be able to `toggle` or `kill` it.
### - Delayed Asynchronous Statements and FunctionsAsynchronous delayed statement:
```javascript
Thread.spawn( () => {
console.log('1 second has passed.');
}, 1000);
```
Anonymous asynchronous delayed function:
```javascript
Thread.spawn( function () {
console.log('1 second has passed.');
}, 1000);
```
These will execute `1000ms` (one second) after they are declared### - Asynchronous Statements and Functions
Asynchronous statement:
```javascript
Thread.do( async () => {
console.log('Code has been executed asynchronously.');
});
```
Anonymous asynchronous function:
```javascript
Thread.do( async function () {
console.log('Code has been executed asynchronously.');
});
```
These will execute immediately and asynchronously once they are called.## Contributing
Contributors are welcome!