2018-08-04 15:53:22 +00:00
|
|
|
import { expect, tap } from '@pushrocks/tapbundle';
|
|
|
|
import taskbuffer = require('../ts/index');
|
2017-06-17 14:56:33 +00:00
|
|
|
|
2018-08-04 15:53:22 +00:00
|
|
|
import * as smartpromise from '@pushrocks/smartpromise';
|
|
|
|
import * as smartdelay from '@pushrocks/smartdelay';
|
2017-06-17 14:56:33 +00:00
|
|
|
|
|
|
|
let flowTask1 = new taskbuffer.Task({
|
|
|
|
taskFunction: (x: number) => {
|
2018-08-04 15:53:22 +00:00
|
|
|
let done = smartpromise.defer();
|
|
|
|
console.log('flowTask1');
|
|
|
|
console.log(x);
|
|
|
|
done.resolve(x);
|
|
|
|
return done.promise;
|
2017-06-17 14:56:33 +00:00
|
|
|
}
|
2018-08-04 15:53:22 +00:00
|
|
|
});
|
2017-06-17 14:56:33 +00:00
|
|
|
|
|
|
|
let flowTaskBuffered = new taskbuffer.Task({
|
|
|
|
taskFunction: (x: number) => {
|
2018-08-04 15:53:22 +00:00
|
|
|
let done = smartpromise.defer();
|
|
|
|
console.log('flowTask1');
|
|
|
|
console.log(x);
|
|
|
|
done.resolve(x);
|
|
|
|
return done.promise;
|
2017-06-17 14:56:33 +00:00
|
|
|
},
|
|
|
|
buffered: true,
|
|
|
|
bufferMax: 1
|
2018-08-04 15:53:22 +00:00
|
|
|
});
|
2017-06-17 14:56:33 +00:00
|
|
|
|
|
|
|
let flowTask2 = new taskbuffer.Task({
|
|
|
|
taskFunction: (x: number) => {
|
2018-08-04 15:53:22 +00:00
|
|
|
let done = smartpromise.defer();
|
|
|
|
console.log('flowTask2');
|
|
|
|
console.log(x);
|
|
|
|
done.resolve(x);
|
|
|
|
return done.promise;
|
2017-06-17 14:56:33 +00:00
|
|
|
},
|
|
|
|
preTask: flowTask1
|
2018-08-04 15:53:22 +00:00
|
|
|
});
|
2017-06-17 14:56:33 +00:00
|
|
|
|
|
|
|
let flowTask3 = new taskbuffer.Taskchain({
|
2018-08-04 15:53:22 +00:00
|
|
|
taskArray: [flowTask1, flowTask2]
|
|
|
|
});
|
2017-06-17 14:56:33 +00:00
|
|
|
|
|
|
|
tap.test('should let a value flow through a task', async () => {
|
2018-08-04 15:53:22 +00:00
|
|
|
let result = await flowTask1.trigger(12);
|
|
|
|
expect(result).to.equal(12);
|
|
|
|
});
|
2017-06-17 14:56:33 +00:00
|
|
|
|
2017-06-17 15:29:26 +00:00
|
|
|
tap.test('expect values to flow between tasks', async () => {
|
2018-08-04 15:53:22 +00:00
|
|
|
let result = await flowTask2.trigger(12);
|
|
|
|
expect(result).to.equal(12);
|
|
|
|
});
|
2017-06-17 14:56:33 +00:00
|
|
|
|
2017-06-17 15:29:26 +00:00
|
|
|
tap.test('expect values to flow between tasks when buffered', async () => {
|
2018-08-04 15:53:22 +00:00
|
|
|
let result = await flowTaskBuffered.trigger(12);
|
|
|
|
expect(result).to.equal(12);
|
|
|
|
});
|
2017-06-17 14:56:33 +00:00
|
|
|
|
2017-06-17 15:29:26 +00:00
|
|
|
tap.test('expect values to flow between tasks in Taskchain', async () => {
|
2018-08-04 15:53:22 +00:00
|
|
|
let result = await flowTask3.trigger(12);
|
|
|
|
expect(result).to.equal(12);
|
|
|
|
});
|
2017-06-17 14:56:33 +00:00
|
|
|
|
2018-08-04 15:53:22 +00:00
|
|
|
tap.start();
|