Update Readme and clarify use of Promises.

This commit is contained in:
LosslessBot 2016-05-04 04:17:59 +02:00
parent 38d02a3ac2
commit 58ac5745a1
3 changed files with 14 additions and 2 deletions

View File

@ -16,4 +16,10 @@ npm install taskbuffer --save
* A Task in its most simple form is a function that is executed when the task runs. * A Task in its most simple form is a function that is executed when the task runs.
* It can have a preTaska and an afterTask (those are run before or after the main function whenever the task is called) * It can have a preTaska and an afterTask (those are run before or after the main function whenever the task is called)
* A Task can be buffered. That means it can be called multiple times in a very short time. However execution happens in line: meaning execution of the task's main function is on halt until the previous task call has finished. * A Task can be buffered. That means it can be called multiple times in a very short time. However execution happens in line: meaning execution of the task's main function is on halt until the previous task call has finished.
* Task.trigger() and Task.triggerBuffered() always return a Promise;
* Task.triggered() is an ObservableStram that emits events every time a task is promised.
* Task is compatible to gulp streams.
#### Taskchain
* Multiple Tasks can be combined in a bigger task using a Taskchain. Taskchain extends Task. * Multiple Tasks can be combined in a bigger task using a Taskchain. Taskchain extends Task.

View File

@ -26,7 +26,8 @@
"beautylog": "^2.1.1", "beautylog": "^2.1.1",
"npmts": "^3.1.2", "npmts": "^3.1.2",
"projectinfo": "0.0.2", "projectinfo": "0.0.2",
"q": "^1.4.1" "q": "^1.4.1",
"rx": "^4.1.0"
}, },
"devDependencies": { "devDependencies": {
"should": "^8.2.2" "should": "^8.2.2"

View File

@ -27,6 +27,7 @@ export class Task {
} }
} }
trigger(){ trigger(){
let done = plugins.Q.defer();
helpers.runTask(this.preTask) helpers.runTask(this.preTask)
.then(function(){ .then(function(){
@ -34,6 +35,10 @@ export class Task {
.then(function(){ .then(function(){
}) })
.then(function(){
done.resolve();
});
return done.promise;
}; };
triggerBuffered(){ triggerBuffered(){
var done = plugins.Q.defer(); var done = plugins.Q.defer();