Skip to content

Commit

Permalink
Task class
Browse files Browse the repository at this point in the history
  • Loading branch information
Ni55aN committed Oct 30, 2017
1 parent b181b1e commit d46b40d
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/engine.js → src/engine/engine.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component } from './component';
import { Utils } from './utils';
import { Component } from '../component';
import { Utils } from '../utils';

var State = { AVALIABLE:0, PROCESSED: 1, ABORT: 2};

Expand Down
62 changes: 62 additions & 0 deletions src/engine/task.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
export class Task {

constructor(inputs, action) {
this.inputs = inputs;
this.action = action;
this.next = [];
this.outputData = null;
this.closed = [];

this.getOptions().forEach(input => {
input.forEach(con => {
con.task.next.push({index: con.index, task: this});
})
});
}

getOptions() {
return this.inputs.filter(input => input[0] && input[0].task)
}

getOutputs() {
return this.inputs.filter(input => input[0] && input[0].get);
}

reset() {
this.outputData = null;
}

run(data) {
var inputs = this.getOutputs().map(input => {
return input.map(con => {
if (con) {
con.run();
return con.get();
}
})
});

if (!this.outputData) {
this.outputData = this.action(inputs, data);

this.next.filter(f => !this.closed.includes(f.index)).forEach(f => f.task.run());
}
}

option(index) {
var task = this;

return {task, index}
}

output(index) {
var task = this;

return {
run: task.run.bind(task),
get() {
return task.outputData[index];
}
}
}
}
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Component } from './component';
import { ContextMenu } from './contextmenu';
import { Control } from './control';
import { Engine } from './engine';
import { Engine } from './engine/engine';
import { Group } from './group';
import { Input } from './input';
import { Node } from './node';
import { NodeEditor } from './editor';
import { Output } from './output';
import { Socket } from './socket';
import { Task } from './engine/task';

export {
Component,
Expand All @@ -19,5 +20,6 @@ export {
Input,
Node,
Output,
Socket
Socket,
Task
}

0 comments on commit d46b40d

Please sign in to comment.