Skip to content

Commit

Permalink
v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rjrodger committed May 13, 2020
1 parent b8948d8 commit 1aa1035
Show file tree
Hide file tree
Showing 6 changed files with 355 additions and 362 deletions.
16 changes: 8 additions & 8 deletions ordu.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ordu.js.map

Large diffs are not rendered by default.

37 changes: 15 additions & 22 deletions ordu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,15 @@ import * as Topo from '@hapi/topo'
import Nua from 'nua'
import StrictEventEmitter from 'strict-event-emitter-types'




export { Ordu, LegacyOrdu }


interface Events {
'task-result': TaskResult
'task-end': { result: TaskResult, operate: Operate, data: any }
'task-end': { result: TaskResult; operate: Operate; data: any }
}

type OrduEmitter = StrictEventEmitter<EventEmitter, Events>


interface OrduIF {
add(td: TaskDef): void
add(td: TaskDef[]): void
Expand Down Expand Up @@ -81,7 +76,7 @@ class Task {
this.name = taskdef.name || 'task' + Task.count
this.before = strarr(taskdef.before)
this.after = strarr(taskdef.after)
this.exec = taskdef.exec || ((_: Spec) => { })
this.exec = taskdef.exec || ((_: Spec) => {})
this.if = taskdef.if || void 0
this.meta = {
order: Task.count++,
Expand Down Expand Up @@ -127,7 +122,7 @@ class TaskResult {

type Operate = {
stop: boolean
err?: Error,
err?: Error
async?: boolean
}

Expand All @@ -144,8 +139,7 @@ type ExecResult = {

type Operator = (r: TaskResult, ctx: any, data: object) => Operate


class Ordu extends (EventEmitter as { new(): OrduEmitter }) implements OrduIF {
class Ordu extends (EventEmitter as { new (): OrduEmitter }) implements OrduIF {
private _opts: any

private _topo: {
Expand All @@ -161,7 +155,7 @@ class Ordu extends (EventEmitter as { new(): OrduEmitter }) implements OrduIF {

this._opts = {
debug: false,
...opts
...opts,
}

this._topo = new Topo.Sorter()
Expand Down Expand Up @@ -236,7 +230,7 @@ class Ordu extends (EventEmitter as { new(): OrduEmitter }) implements OrduIF {
let operate: Operate | Promise<Operate> = {
stop: false,
err: void 0,
async: false
async: false,
}
let tasklog: any[] = []

Expand All @@ -252,7 +246,7 @@ class Ordu extends (EventEmitter as { new(): OrduEmitter }) implements OrduIF {
end: Number.MAX_SAFE_INTEGER,
index: taskI,
total: tasks.length,
async: false
async: false,
}

if (this._task_if(task, spec.data)) {
Expand Down Expand Up @@ -280,8 +274,7 @@ class Ordu extends (EventEmitter as { new(): OrduEmitter }) implements OrduIF {
if (operate instanceof Promise) {
operate = (await operate) as Operate
operate.async = true
}
else {
} else {
operate.async = false
}

Expand All @@ -290,7 +283,7 @@ class Ordu extends (EventEmitter as { new(): OrduEmitter }) implements OrduIF {
operate = {
stop: true,
err: operate_ex,
async: false
async: false,
}
}

Expand All @@ -301,12 +294,12 @@ class Ordu extends (EventEmitter as { new(): OrduEmitter }) implements OrduIF {
task,
result,
operate,
data: this._opts.debug ? JSON.parse(JSON.stringify(spec.data)) : void 0
data: this._opts.debug ? JSON.parse(JSON.stringify(spec.data)) : void 0,
})
this.emit('task-end', {
result,
operate,
data: this._opts.debug ? JSON.parse(JSON.stringify(spec.data)) : void 0
data: this._opts.debug ? JSON.parse(JSON.stringify(spec.data)) : void 0,
})

if (operate.stop) {
Expand Down Expand Up @@ -341,7 +334,7 @@ class Ordu extends (EventEmitter as { new(): OrduEmitter }) implements OrduIF {
return {
stop: true,
err: r.err,
async: false
async: false,
}
}

Expand All @@ -353,7 +346,7 @@ class Ordu extends (EventEmitter as { new(): OrduEmitter }) implements OrduIF {
return {
stop: true,
err: new Error('Unknown operation: ' + r.op),
async: false
async: false,
}
}
}
Expand Down Expand Up @@ -457,13 +450,13 @@ function LegacyOrdu(opts?: any): any {
}

function api_tasknames() {
return tasks.map(function(v) {
return tasks.map(function (v) {
return v.name
})
}

function api_taskdetails() {
return tasks.map(function(v) {
return tasks.map(function (v) {
return v.name + ':{tags:' + v.tags + '}'
})
}
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ordu",
"version": "1.2.0",
"version": "1.3.0",
"description": "Execute functions in a configurable order, modifying a shared data structure.",
"homepage": "https://github.com/rjrodger/ordu",
"keywords": [
Expand Down

0 comments on commit 1aa1035

Please sign in to comment.