Process tasks serially.
npm install --save @tawaship/task
import { Task } from '@tawaship/task';
// or
const { Task } = require('@tawaship/task');
git clone https://github.com/tawaship/Task
cd Emitter
npm install
npm run build
<script src="/path/to/dist/Task.min.js"></script>
let a = 0;
const task = new Task(
function() {
a++;
}
);
task.done();
console.log(a); // 1
task.done();
console.log(a); // 2
const task = new Task([
function() {
return task.next().done();
},
function() {
return 3;
}
]);
console.log(task.done()); // 3
const task = new Task([
function() {
return 1
},
function() {
return 2;
},
function() {
return 3;
}
]);
console.log(task.first().done()); // 1
console.log(task.next().done()); // 2
console.log(task.prev().done()); // 1
console.log(task.to(2).done()); // 3
const task = new Task([
function() {
return 1
},
function() {
return 2;
},
function() {
return 3;
},
function() {
return 4;
}
]);
task.enabled = false;
console.log(task.first().done()); // undefined
console.log(task.next().done()); // undefined
console.log(task.prev().done()); // undefined
console.log(task.to(2).done()); // undefined
const task = new Task([
function() {
return 1
}
])
.add(function() {
return 2;
});
console.log(task.next().done()); // 2
const task = new Task([
function() {
return 1
}
])
.reset();
console.log(task.first().done()); // undefined
const task = new Task(
function(a, b, c) {
console.log(a, b, c); // 1 2 3
}
);
task.done(1, 2, 3);
const task = new Task([
function() {
return 1;
},
function() {
return 2;
}
]);
task.first().done();
console.log(task.value); // 1
task.next().done();
console.log(task.value); // 2
let a = {hoge: 1};
const task = new Task(
function() {
this.moga = 2;
return this;
}
, a);
console.log(task.done()); // { hoge: 1, moga: 2 }
However, using the arrow function invalidates the context specification.
// on window
let a = {hoge: 1};
const task = new Task(
() => {
return this;
}
, a);
console.log(task.done()); // Window
let a = {hoge: 1};
const task = new Task(
function() {
this.moga = 2;
return this;
}
, a);
task.first().finish().done();
console.log(a); // {hoge: 1}
Generated using TypeDoc