queueobj 8.0.2 → 9.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,11 +3,11 @@ Queue javascript objects dynamically then process the queue according to the app
3
3
 
4
4
  Included tag appenders:
5
5
 
6
- * all - asynchronous - process all added objects.
7
- * func_all - asynchronous - process custom functions to added objects.
8
- * top_one - asynchronous - process only the object in the 0(zero) position of the process array.
9
- * bottom_one - asynchronous - process only the object in the last position of the process array.
10
- * sync_all - synchronous - queue and process all objects by items as well as custom functions.
6
+ * all - synchronous - process all added objects.
7
+ * func_all - synchronous - process custom functions to added objects.
8
+ * top_one - synchronous - process only the object in the 0(zero) position of the process array.
9
+ * bottom_one - synchronous - process only the object in the last position of the process array.
10
+ * sync_all - synchronous - All appenders are synchronous now. Sync_all is no different than all .
11
11
  * status - synchronous - queue and process all objects by status.
12
12
  * version - synchronous - queue and process all objects by version.
13
13
 
@@ -46,24 +46,28 @@ var queue = require("queueobj");
46
46
  class test1 {
47
47
  constructor() {
48
48
  this.id = 100
49
+ this.process = this.process.bind(this)
49
50
  }
50
51
 
51
52
  process(callback) {
52
- console.log(`processing test1`.cyan)
53
- callback()
53
+ setTimeout(() => {
54
+ console.log(`processing test1`.cyan)
55
+ console.log(`some async process`)
56
+ callback({success: {msg: `processing all (${this.id})`}})
57
+ }, 3000)
54
58
  }
55
59
  }
56
60
 
57
61
  class test2 {
58
62
  constructor() {
59
63
  this.id = 200
64
+ this.process = this.process.bind(this)
60
65
  }
61
66
 
62
67
  process(callback) {
63
- let msg = `some kinda problem here`
64
- console.log(`processing test2`.cyan)
65
- //callback({error: {msg: msg}}) //this will show errors
66
- callback() //this will show no errors
68
+ let msg = `some kinda problem here in id(${this.id})`
69
+ // callback({error: {msg: msg}}) //this will show errors
70
+ callback({success: {msg: `processing all (${this.id})}`}}) //this will show no errors
67
71
  }
68
72
 
69
73
  ping() {
@@ -74,14 +78,11 @@ class test2 {
74
78
  class test3 {
75
79
  constructor() {
76
80
  this.id = 300
81
+ this.process = this.process.bind(this)
77
82
  }
78
83
 
79
84
  process(callback) {
80
- setTimeout(()=>{
81
- console.log(`processing test3`.cyan)
82
- console.log(`some async process`)
83
- callback()
84
- }, 2000)
85
+ callback({success: {msg: `processing all (${this.id})}`}})
85
86
  }
86
87
  }
87
88
 
@@ -94,64 +95,21 @@ class test4 {
94
95
 
95
96
  custom_function(callback) {
96
97
  let msg = `custom func problem here id(${this.id})`
97
- console.log(`processing test4`.cyan)
98
- //callback({error: {msg: msg}}) //this will show errors
99
- callback() //this will show no errors
98
+ setTimeout(() => {
99
+ // callback({error: {msg: msg}}) //this will show errors
100
+ callback({success: {msg: `processing all (${this.id})}`}}) //this will show no errors
101
+ }, 3000)
100
102
  }
101
103
  }
102
104
  let tst4 = new test4()
103
- let qObj = new queue(), props = { appender: 'sync', stats: true }
105
+ let qObj = new queue(), props = { appender: 'sync_all' }
104
106
 
105
107
  qObj.load(props).add(new test1()).add(new test2()).add(new test3()).add(tst4.custom_function)
106
108
 
107
- qObj.await({ items: [0, 1] }).then(res => {
108
- console.log(`1) done with items[0,1]: (${res})`.green)
109
- }, err => {
110
- console.log(`1) error[0, 1]: (${err})`.red)
111
- })
112
-
113
- qObj.await({ items: [1, 2] }).then(res => {
114
- console.log(`2) done with items[1,2]: (${res})`.green)
115
- }, err => {
116
- console.log(`2) error[1,2]: (${err})`.red)
117
- })
118
-
119
- qObj.await({ items: [2, 1, 2] }).then(res => {
120
- console.log(`3) done with items[2,1,2]: (${res})`.green)
121
- }, err => {
122
- console.log(`3) error[2, 1, 2]: (${err})`.red)
123
- })
124
-
125
- qObj.await({ items: [2, 3] }).then(res => {
126
- console.log(`4) done with item[2, 3]: (${res})`.green)
127
- }, err => {
128
- console.log(`4) error[2, 3]: (${err})`.red)
129
- })
130
-
131
- qObj.await({ items: [0] }).then(res => {
132
- console.log(`5) done with item[0]: (${res})`.green)
133
- }, err => {
134
- console.log(err.red)
135
- })
136
-
137
- qObj.getObjectById(200).ping()
138
-
139
- qObj.await({ byIds: [300, 200, 100] }).then(res => {
140
- console.log(`6) done with byId: [300, 200, 100] (${res})`.bold.italic.underline.yellow)
141
- }, err => {
142
- console.log(`6) error[300, 200, 100]: (${err})`.red)
143
- })
144
-
145
- qObj.await({ byIds: [100, 300] }).then(res => {
146
- console.log(`7) done with byId: [100, 300] (${res})`.bold.italic.underline.yellow)
147
- }, err => {
148
- console.log(`7) error[100, 300]: (${err})`.red)
149
- })
150
-
151
109
  qObj.process().then(res => {
152
- console.log(`8) done with all sync processing: (${res})`.bold.italic.white)
110
+ console.log(`success with all sync processing: (${JSON.stringify(res)})`.bold.italic.green)
153
111
  }, err => {
154
- console.log(`8) errors with all sync processing: (${err})`.red)
112
+ console.log(`errors with all sync processing: (${JSON.stringify(err)})`.red)
155
113
  })
156
114
 
157
115
  ```
package/app.js CHANGED
@@ -35,7 +35,6 @@ class QueueObj {
35
35
 
36
36
  t.load = t.load.bind(this)
37
37
  t.process = t.process.bind(this)
38
- t.await = t.await.bind(this)
39
38
  t.getParent = t.getParent.bind(this)
40
39
  t.getObjectToProcess = t.getObjectToProcess.bind(this)
41
40
  t.getObjectById = t.getObjectById.bind(this)
@@ -159,38 +158,39 @@ class QueueObj {
159
158
  var t = this
160
159
  try {
161
160
  if (t.all != null) {
162
- obj.getType = (o) => {
161
+ obj._getProperty = (o) => {
163
162
  return 'all'
164
163
  }
165
164
  }
166
165
  if (t.top_one != null) {
167
- obj.getType = (o) => {
166
+ obj._getProperty = (o) => {
168
167
  return 'top_one'
169
168
  }
170
169
  }
171
170
  if (t.bottom_one != null) {
172
171
  t.objs = []
173
- obj.getType = (o) => {
172
+ obj._getProperty = (o) => {
174
173
  return 'bottom_one'
175
174
  }
176
175
  }
177
176
  if (t.func_all != null) {
178
- obj.getType = (o) => {
177
+ obj._getProperty = (o) => {
179
178
  return 'func_all'
180
179
  }
181
180
  }
182
181
  if (t.sync_all != null) {
183
- obj.getType = (o) => {
182
+ obj._getProperty = (o) => {
184
183
  return 'sync_all'
185
184
  }
186
185
  }
187
186
  if (typeof obj.status != 'undefined') {
188
- obj.getType = (o) => {
187
+ obj._getProperty = (o) => {
189
188
  return o.status
190
189
  }
190
+
191
191
  }
192
192
  if (typeof obj.version != 'undefined') {
193
- obj.getType = (o) => {
193
+ obj._getProperty = (o) => {
194
194
  return o.version
195
195
  }
196
196
  }
@@ -217,45 +217,25 @@ class QueueObj {
217
217
  return this.objs
218
218
  }
219
219
 
220
- process() {
220
+ process(props = {}) {
221
221
  try {
222
- var t = this, pro = { dat_array: [] }
223
- switch (t.props.appender) {
222
+ var t = this
223
+ switch (t.props.appender) {
224
224
  case 'all':
225
- pro.dat_array.push('all')
226
- t.all.await(pro)
227
- return t.all.process()
225
+ return t.all.process(props)
228
226
  case 'top_one':
229
- pro.dat_array.push('top_one')
230
- t.top_one.await(pro)
231
- return t.top_one.process()
227
+ return t.top_one.process(props)
232
228
  case 'bottom_one':
233
- pro.dat_array.push('bottom_one')
234
- t.bottom_one.await(pro)
235
- return t.bottom_one.process()
229
+ return t.bottom_one.process(props)
236
230
  case 'func_all':
237
- pro.dat_array.push('func_all')
238
- t.func_all.await(pro)
239
- return t.func_all.process()
231
+ return t.func_all.process(props)
240
232
  case 'sync':
241
233
  case 'sync_all':
242
- pro.dat_array.push('sync_all')
243
- t.sync_all.await(pro)
244
- return t.sync_all.process()
234
+ return t.sync_all.process(props)
245
235
  case 'status':
246
- return t.status.process()
236
+ return t.status.process(props)
247
237
  case 'version':
248
- return t.version.process()
249
- // case 'sync_all':
250
- // t.objs.map((item, i) => {
251
- // pro.items.push(i)
252
- // })
253
- // t.sync.await(pro).then(res => {
254
- // console.log(`done with ${JSON.stringify(pro)}: (${res})`.green)
255
- // }, err => {
256
- // console.log(`error ${JSON.stringify(pro)}: (${err})`.red)
257
- // })
258
- // return t.sync.process()
238
+ return t.version.process(props)
259
239
  default:
260
240
  throw new Error(`nothing to process`)
261
241
  }
@@ -265,28 +245,6 @@ class QueueObj {
265
245
  throw (e)
266
246
  }
267
247
  }
268
-
269
- await(props) {
270
- var t = this, pro
271
- try {
272
- if (t.sync != null) {
273
- pro = { dat_array: props.items }
274
- return t.sync.await(props)
275
- }
276
- if (t.status != null) {
277
- pro = { dat_array: props.status }
278
- return t.status.await(pro)
279
- }
280
- if (t.version != null) {
281
- pro = { dat_array: props.version }
282
- return t.version.await(pro)
283
- }
284
- } catch (e) {
285
- e.message = "queueObj app.js load error: " + e.message
286
- console.log(e.message)
287
- throw (e)
288
- }
289
- }
290
248
  }
291
249
 
292
250
  exports = module.exports = function (props) {
@@ -2,47 +2,140 @@
2
2
  * @author Jim Manton: jrman@risebroadband.net
3
3
  * @since 2017-10-01
4
4
  * lib/appenders/base.js
5
+ * jrm debug 8/4 https://www.npmjs.com/package/temporary-stamp
5
6
  */
6
7
 
7
8
  var colors = require('colors')
8
9
 
10
+ class process_all_obj {
11
+ constructor(props) {
12
+ let t = this
13
+ t.parent = props.parent
14
+ t.objs = t.parent.getParent().getObjs()
15
+ t.status = 'process'
16
+ t.process_objs_item = 0
17
+ t.process_props_item = 0
18
+ t.await_item = 0
19
+ t.any_errors = false
20
+
21
+
22
+ t.continueProcessing = t.continueProcessing.bind(t)
23
+ }
24
+
25
+ process = () => {
26
+ let t = this
27
+ try {
28
+ if (t.process_objs_item >= t.objs.length) {
29
+ if (t.any_errors)
30
+ t.setStatus('finish with errors')
31
+ else
32
+ t.setStatus('finish')
33
+ return
34
+ }
35
+ try {
36
+ let obj, pro, itm
37
+ try {
38
+ obj = t.parent.getParent().getItemToProcess(t.process_objs_item)
39
+ } catch (e) {
40
+ e.message = `base error: (${e.message})`
41
+ throw e
42
+ }
43
+ try {
44
+ pro = (typeof obj == 'function') ? obj : obj.process;
45
+ } catch (e) {
46
+ console.log(`pro error: (${e.message})`.red)
47
+ throw e
48
+ }
49
+ if (typeof t.parent.pro_props != 'undefined' &&
50
+ typeof t.parent.pro_props.property != 'undefined' &&
51
+ typeof t.parent.pro_props.items != 'undefined' &&
52
+ typeof obj._getProperty == 'function') {
53
+ let skip = true
54
+ for (let q = 0; q < t.parent.pro_props.items.length; q++) {
55
+ itm = t.parent.pro_props.items[q]
56
+ if (itm == obj._getProperty(obj)) {
57
+ skip = false
58
+ break
59
+ }
60
+ }
61
+ if (skip) {
62
+ t.continueProcessing()
63
+ return
64
+ }
65
+ }
66
+ t.setStatus('wait')
67
+ pro((obj_props) => {
68
+ try {
69
+ if (typeof obj_props != 'undefined' && typeof obj_props.error != 'undefined') {
70
+ t.any_errors = true
71
+ console.log(`${JSON.stringify(obj_props)}`.red)
72
+ } else {
73
+ console.log(`${JSON.stringify(obj_props)}`.green)
74
+ }
75
+ t.parent.results_array.push(obj_props)
76
+ t.continueProcessing()
77
+ } catch (e) {
78
+ console.log(`pro obj error: (${e.message})`.red)
79
+ throw e
80
+ }
81
+ })
82
+ } catch (e) {
83
+ e.message = `10.01 error: ${e.message} `
84
+ throw e
85
+ }
86
+ } catch (e) {
87
+ e.message = `process_all_obj error: ${e.message} `
88
+ throw e
89
+ }
90
+ }
91
+
92
+ continueProcessing = () => {
93
+ let t = this
94
+ t.process_objs_item++
95
+ t.setStatus('process')
96
+ t.parent.process_all()
97
+ }
98
+
99
+ getStatus = () => {
100
+ return this.status
101
+ }
102
+
103
+ setStatus = (v) => {
104
+ this.status = v
105
+ }
106
+ }
107
+
9
108
  exports = module.exports = class base {
10
109
  constructor(props) {
11
110
  let t = this
12
111
  t.await_array = []
13
112
  t.resolve_array = []
14
113
  t.reject_array = []
15
- t.process_objs_item = 0
16
- t.process_props_item = 0
17
- t.any_errors = false
114
+ t.results_array = []
18
115
  t.getParent = props.getParent
19
116
  t.dt_start = null
20
117
  t.dt_end = null
118
+ t.process_all_obj = null
119
+ t.pro_props = []
21
120
 
22
121
  t.process = t.process.bind(this)
23
122
  t.process_all = t.process_all.bind(this)
24
123
  }
25
124
 
125
+ // await(props) {
126
+ // let t = this
127
+ // t.await_array.push(props)
128
+ // return new Promise((resolve, reject) => {
129
+ // t.resolve_array.push(resolve)
130
+ // t.reject_array.push(reject)
131
+ // });
132
+ // }
26
133
 
27
- await(props) {
28
- let t = this
29
- t.await_array.push(props)
30
- return new Promise((resolve, reject) => {
31
- t.resolve_array.push(resolve)
32
- t.reject_array.push(reject)
33
- });
34
- }
35
-
36
- process() {
134
+ process(props) {
37
135
  let t = this
38
- t.process_objs_item = 0
39
- t.process_props_item = 0
40
- t.await_item = 0
41
136
  t.dt_start = new Date(); // start measuring time
42
- // t.await_array = []
43
- // t.resolve_array = []
44
- // t.reject_array = []
45
- // t.status_props_array = []
137
+
138
+ t.pro_props = props
46
139
 
47
140
  return new Promise((resolve, reject) => {
48
141
  t.resolve_array.push(resolve)
@@ -52,115 +145,45 @@ exports = module.exports = class base {
52
145
  }
53
146
 
54
147
  getStats() {
55
- let t = this, msg, st = `${t.dt_start}`.green, ed = `${t.dt_end}`.green, ml = `${t.dt_end - t.dt_start}`.green
56
- msg = `success`.green
57
- if (t.getParent().getStats())
58
- msg += `\nstart(${st}) end(${ed}) milliseconds(${ml})`
59
- return msg
148
+ let t = this, json_ret = { execution_time: 'status is set to false' }, st = `${t.dt_start} `.green, ed = `${t.dt_end} `.green, ml = `${t.dt_end - t.dt_start} `.green
149
+ json_ret.responses = t.results_array
150
+ if (t.getParent().getStats()) {
151
+ json_ret.execution_time = `start`.green
152
+ json_ret.execution_time += `(${st}) end(${ed}) milliseconds(${ml})`
153
+ }
154
+ return json_ret
60
155
  }
61
156
 
62
- process_all() {
63
- let t = this, obj, pro, itm, msg, itm_type, props_type, datA
157
+ process_all = () => {
158
+ let t = this, _continue
159
+ if (t.process_all_obj == null) {
160
+ t.process_all_obj = new process_all_obj({ parent: t })
161
+ }
162
+
163
+ _continue = false
64
164
  try {
65
- try {
66
- if (t.process_objs_item >= t.getParent().getObjs().length) {
67
- t.await_item++
165
+ switch (t.process_all_obj.getStatus()) {
166
+ case 'process':
167
+ t.process_all_obj.process()
168
+ _continue = true
169
+ break
170
+ case 'finish with errors':
171
+ t.reject_array[t.reject_array.length - 1](t.getStats())
172
+ break
173
+ case 'finish':
68
174
  t.resolve_array[t.resolve_array.length - 1](t.getStats())
175
+ break
176
+ case 'wait':
69
177
  return
70
- }
71
- } catch (e) {
72
- return
178
+ default:
179
+ throw new Error(`status(${t.process_all_obj.getStatus()}) does not exist`)
73
180
  }
74
- try {
75
- datA = t.await_array[t.await_item].dat_array
76
- } catch (e) {
77
- return
78
- }
79
- try {
80
181
 
81
- datA.map((dat_item, i) => {
82
- if (i == t.process_props_item) {
83
- if (t.process_props_item < datA.length) {
84
- if ((t.await_item) >= t.await_array.length) {
85
- t.resolve_array[t.resolve_array.length - 1](t.getStats())
86
- return
87
- }
88
- t.getParent().getObjs().map((pItem, x) => {
89
- if (x == t.process_objs_item) {
90
- try {
91
- obj = t.getParent().getItemToProcess(x)
92
- } catch (e) {
93
- e.message = `base error: (${e.message})`
94
- throw e
95
- }
96
- if (typeof obj != 'undefined' && typeof obj.getType != 'function') {
97
- obj.getType = (o) => { return t.aname }
98
- }
99
- if (obj.getType(obj) == dat_item) {
100
- try {
101
- pro = (typeof obj == 'function') ? obj : obj.process;
102
- } catch (e) {
103
- console.log(`pro error: (${e.message})`.red)
104
- throw e
105
- }
106
-
107
- pro((obj_props) => {
108
- try {
109
-
110
- if (typeof obj_props != 'undefined') {
111
- if (typeof obj_props.error != 'undefined' &&
112
- typeof obj_props.error.msg != 'undefined' &&
113
- typeof obj_props.error.msg == 'string') {
114
- msg = `error: ${obj_props.error.msg}`
115
- msg += (typeof obj.id != 'undefined') ? ` id(${obj.id})` : ``;
116
- t.any_errors = true
117
- t.reject_array[t.reject_array.length - 1](msg)
118
- } else {
119
- console.log(`${JSON.stringify(obj_props)}`.green)
120
- }
121
- }
122
- t.process_objs_item++
123
- if (t.process_props_item < datA.length) {
124
- t.process_all()
125
- } else {
126
- t.dt_end = new Date();
127
- t.resolve_array[t.process_props_item - 1](t.getStats())
128
- t.process_props_item = 0
129
- t.process_objs_item = 0
130
- }
131
- } catch (e) {
132
- console.log(`proessing error: (${e.message})`.red)
133
- throw e
134
- }
135
- })
136
- } else {
137
- t.process_objs_item++
138
- if (t.process_objs_item >= t.getParent().getObjs().length) {
139
- t.resolve_array[t.resolve_array.length - 1](t.getStats())
140
- }
141
- }
142
- } else {
143
- if (t.process_objs_item >= t.getParent().getObjs().length) {
144
- t.process_objs_item = 0
145
- t.process_props_item++
146
- if (t.process_props_item >= datA.length) {
147
- t.await_item++
148
- t.process_props_item = 0
149
- if (t.await_item <= t.await_array.length)
150
- t.process_all()
151
- }
152
- }
153
- }
154
- })
155
- }
156
- }
157
- })
158
- } catch (e) {
159
- e.message = `await error: ${e.message}`
160
- throw e
161
- }
182
+ if (_continue)
183
+ t.process_all()
162
184
  } catch (e) {
163
- console.log(`process_all error: ${e.message}`.red)
185
+ e.message = `process_all error: ${e.message} `
186
+ throw e
164
187
  }
165
188
  }
166
189
  }
package/package.json CHANGED
@@ -2,13 +2,13 @@
2
2
  "author": {
3
3
  "name": "Jim Manton"
4
4
  },
5
- "version": "8.0.2",
5
+ "version": "9.0.2",
6
6
  "bundleDependencies": false,
7
7
  "dependencies": {
8
8
  "chai": "^4.3.3",
9
9
  "colors": "^1.4.0",
10
10
  "compare-json-difference": "^0.1.3",
11
- "mocha": "^9.1.3"
11
+ "mocha": "^10.0"
12
12
  },
13
13
  "scripts": {
14
14
  "start": "node app.ts",
@@ -19,9 +19,7 @@
19
19
  "processing",
20
20
  "appenders",
21
21
  "javascript",
22
- "asynchronous",
23
22
  "synchronous",
24
- "await",
25
23
  "objects",
26
24
  "promises",
27
25
  "mocha"
package/test/package.js CHANGED
@@ -6,13 +6,13 @@ const packageMock = {
6
6
  "author": {
7
7
  "name": "Jim Manton"
8
8
  },
9
- "version": "8.0.2",
9
+ "version": "9.0.2",
10
10
  "bundleDependencies": false,
11
11
  "dependencies": {
12
12
  "chai": "^4.3.3",
13
13
  "colors": "^1.4.0",
14
14
  "compare-json-difference": "^0.1.3",
15
- "mocha": "^9.1.3"
15
+ "mocha": "^10.0"
16
16
  },
17
17
  "scripts": {
18
18
  "start": "node app.ts",
@@ -23,9 +23,7 @@ const packageMock = {
23
23
  "processing",
24
24
  "appenders",
25
25
  "javascript",
26
- "asynchronous",
27
26
  "synchronous",
28
- "await",
29
27
  "objects",
30
28
  "promises",
31
29
  "mocha"
package/test_all.js CHANGED
@@ -3,38 +3,41 @@ var colors = require('colors')
3
3
  var queue = require("./app.js");
4
4
 
5
5
  class test1 {
6
- process(callback){
7
- callback({success: `processing all test1`})
6
+ process(callback) {
7
+ callback({ success: { msg: `processing all test1` } })
8
8
  }
9
9
  }
10
10
 
11
11
  class test2 {
12
- constructor(obj){
13
- obj.add(new test4())
14
- }
15
12
 
16
- process(callback){
17
- callback({success: `processing all test2`})
13
+ process(callback) {
14
+ callback({ success: { msg: `processing all test2` } })
18
15
  }
19
16
  }
20
17
 
21
18
  class test3 {
22
- process(callback){
23
- // callback({success: `processing all test3`})
24
- callback({error: {msg: `error test3`}})
19
+ process(callback) {
20
+ callback({success: { msg: `processing all test3` }})
21
+ // callback({ error: { msg: `there is some problem thrown here on test3` } })
25
22
  }
26
23
  }
27
24
 
28
25
  class test4 {
29
- process(callback){
30
- callback({success: `processing all test4`})
26
+ process(callback) {
27
+ callback({ success: { msg: `processing all test4` } })
31
28
  }
32
29
  }
33
30
 
34
- let qObj = new queue(), props = { appender: 'all', stats: true}
31
+ let qObj = new queue(), props = { appender: 'all', stats: true }
35
32
 
36
- qObj.load(props).add(new test1()).add(new test2(qObj)).add(new test3()).process({}).then(res => {
37
- console.log(res)
33
+ qObj.load(props).add(new test1()).add(new test2()).add(new test3()).add(new test4()).process({}).then(res => {
34
+ console.log(`success with all processing: (${JSON.stringify(res)})`.bold.italic.green)
38
35
  }, err => {
39
- console.log(`errors with all processing: (${err})`.red)
36
+ // console.log(`error with all processing: (${JSON.stringify(err)})`.red) //show all results
37
+ console.log(`error with all processing: (${err.execution_time})`.red) //show the execution time
38
+ err.responses.map((jItem, i) => {
39
+ if (typeof jItem.error != 'undefined' && typeof jItem.error.msg != 'undefined') {
40
+ console.log(`error: ${jItem.error.msg}`.red) //show the error
41
+ }
42
+ })
40
43
  })
@@ -4,29 +4,26 @@ var queue = require("./app.js");
4
4
 
5
5
  class test1 {
6
6
  process(callback) {
7
- console.log(`processing test1`.cyan)
8
- callback()
7
+ callback({success: {msg: `processing test1`}})
9
8
  }
10
9
  }
11
10
 
12
11
  class test2 {
13
12
  process(callback) {
14
- console.log(`processing test2`.cyan)
15
- callback()
13
+ callback({success: {msg: `processing test2`}})
16
14
  }
17
15
  }
18
16
 
19
17
  class test3 {
20
18
  process(callback) {
21
- console.log(`processing test3`.cyan)
22
- callback()
19
+ callback({success: {msg: `processing test3`}})
23
20
  }
24
21
  }
25
22
 
26
- let qObj = new queue(), props = { appender: 'bottom_one', stats: true}
23
+ let qObj = new queue(), props = { appender: 'bottom_one', stats: false}
27
24
 
28
25
  qObj.load(props).add(new test1()).add(new test2(qObj)).add(new test3()).process({}).then(res => {
29
- console.log(res)
26
+ console.log(`success with all sync processing: (${JSON.stringify(res)})`.bold.italic.green)
30
27
  }, err => {
31
- console.log(`errors with bottom item processing: (${err})`.red)
28
+ console.log(`errors with all sync processing: (${JSON.stringify(err)})`.red)
32
29
  })
package/test_func_all.js CHANGED
@@ -4,15 +4,13 @@ var queue = require("./app.js");
4
4
 
5
5
  class test1 {
6
6
  some_function(callback) {
7
- console.log(`some_function test1`.cyan)
8
- callback()
7
+ callback({success: {msg: `some_function test1`}})
9
8
  }
10
9
  }
11
10
 
12
11
  class test2 {
13
12
  a_func(callback) {
14
- console.log(`a_func test2`.cyan)
15
- callback()
13
+ callback({success: {msg: `a_func test2`}})
16
14
  }
17
15
  }
18
16
 
@@ -21,15 +19,13 @@ class test3 {
21
19
  obj.add(run_func.some_new_func)
22
20
  }
23
21
  cool(callback) {
24
- console.log(`cool test3`.cyan)
25
- callback()
22
+ callback({success: {msg: `cool test3`}})
26
23
  }
27
24
  }
28
25
 
29
26
  class test4 {
30
27
  some_new_func(callback) {
31
- console.log(`some_new_func test4`.cyan)
32
- callback()
28
+ callback({success: {msg: `some_new_func test4`}})
33
29
  }
34
30
  }
35
31
 
@@ -41,6 +37,8 @@ let tst1 = new test1(),
41
37
  tst3 = new test3(qObj, tst4)
42
38
 
43
39
  qObj.load(props).add(tst1.some_function).add(tst2.a_func).add(tst3.cool).process().then(res => {
44
- console.log(`success processing`.green)
40
+ console.log(`success with func_all processing: (${JSON.stringify(res)})`.bold.italic.green)
41
+ }, err => {
42
+ console.log(`errors with func_all processing: (${JSON.stringify(err)})`.red)
45
43
  })
46
44
 
package/test_status.js CHANGED
@@ -17,9 +17,7 @@ class test1 {
17
17
  }
18
18
 
19
19
  process(callback) {
20
- console.log(`processing test1`.cyan)
21
- this.status = "done"
22
- callback()
20
+ callback({success: {msg: `processing test1 id(${this.id}) status(${this.status})`}})
23
21
  }
24
22
  }
25
23
 
@@ -27,18 +25,15 @@ class test2 {
27
25
  constructor() {
28
26
  let t = this
29
27
  t.id = 200
30
- t.status = "new"
28
+ t.status = "error"
31
29
 
32
30
  t.process = t.process.bind(t)
33
31
  }
34
32
 
35
33
  process(callback) {
36
34
  let t = this, msg = `some kinda problem here`
37
- console.log(`processing test2`.cyan)
38
- t.status = "error"
39
35
  // callback({error: {msg: msg}}) //this will show errors
40
- t.status = "done"
41
- callback() //this will show no errors
36
+ callback({success: {msg: `processing test2 id(${this.id}) status(${this.status})`}}) //this will show no errors
42
37
  }
43
38
 
44
39
  ping() {
@@ -56,10 +51,7 @@ class test3 {
56
51
  }
57
52
 
58
53
  process(callback) {
59
- console.log(`processing test3`.cyan)
60
- console.log(`some async process`)
61
- this.status = "done"
62
- callback()
54
+ callback({success: {msg: `processing test3 id(${this.id}) status(${this.status})`}}) //this will show no errors
63
55
  }
64
56
  }
65
57
 
@@ -73,30 +65,22 @@ class test4 {
73
65
  }
74
66
 
75
67
  process(callback) {
76
- console.log(`processing test4`.cyan)
77
- this.status = "done"
78
- callback()
68
+ callback({success: {msg: `processing test4 id(${this.id}) status(${this.status})`}}) //this will show no errors
79
69
  }
80
70
  }
81
71
 
82
- let qObj = new queue(), props = { appender: 'status' }
72
+ let qObj = new queue(), props = { appender: 'status', stats: true }
83
73
 
84
74
  qObj.load(props).add(new test1()).add(new test2()).add(new test3()).add(new test4())
85
75
 
86
- qObj.await({ status: ['new', 'secondary'] }).then(res => {
87
- console.log(`1) done with status'[new', 'secondary']: (${res})`.green)
76
+ qObj.process({ property: 'status', items: ['init'] }).then(res => {
77
+ console.log(`success with status processing: (${JSON.stringify(res)})`.bold.italic.green)
88
78
  }, err => {
89
- console.log(`1) error['new', 'secondary']: (${err})`.red)
79
+ console.log(`errors with status processing: (${JSON.stringify(err)})`.red)
90
80
  })
91
81
 
92
- qObj.await({ status: ['third'] }).then(res => {
93
- console.log(`2) done with status['third']: (${res})`.green)
94
- }, err => {
95
- console.log(`2) error['third']: (${err})`.red)
96
- })
97
-
98
- qObj.process().then(res => {
99
- console.log(`3) done with status processing: (${res})`.bold.italic.blue)
100
- }, err => {
101
- console.log(`3) errors with status processing: (${err})`.red)
102
- })
82
+ // qObj.process({ property: 'status', items: ['error'] }).then(res => {
83
+ // console.log(`success with status error processing: (${JSON.stringify(res)})`.bold.italic.green)
84
+ // }, err => {
85
+ // console.log(`errors with status error processing: (${JSON.stringify(err)})`.red)
86
+ // })
package/test_sync_all.js CHANGED
@@ -10,13 +10,14 @@ var queue = require("./app.js");
10
10
  class test1 {
11
11
  constructor() {
12
12
  this.id = 100
13
+ this.process = this.process.bind(this)
13
14
  }
14
15
 
15
16
  process(callback) {
16
- setTimeout(()=>{
17
+ setTimeout(() => {
17
18
  console.log(`processing test1`.cyan)
18
19
  console.log(`some async process`)
19
- callback()
20
+ callback({success: {msg: `processing all (${this.id})`}})
20
21
  }, 3000)
21
22
  }
22
23
  }
@@ -24,13 +25,13 @@ class test1 {
24
25
  class test2 {
25
26
  constructor() {
26
27
  this.id = 200
28
+ this.process = this.process.bind(this)
27
29
  }
28
30
 
29
31
  process(callback) {
30
- let msg = `some kinda problem here`
31
- console.log(`processing test2`.cyan)
32
- //callback({error: {msg: msg}}) //this will show errors
33
- callback() //this will show no errors
32
+ let msg = `some kinda problem here in id(${this.id})`
33
+ // callback({error: {msg: msg}}) //this will show errors
34
+ callback({success: {msg: `processing all (${this.id})}`}}) //this will show no errors
34
35
  }
35
36
 
36
37
  ping() {
@@ -41,11 +42,11 @@ class test2 {
41
42
  class test3 {
42
43
  constructor() {
43
44
  this.id = 300
45
+ this.process = this.process.bind(this)
44
46
  }
45
47
 
46
48
  process(callback) {
47
- console.log(`processing test3`.cyan)
48
- callback()
49
+ callback({success: {msg: `processing all (${this.id})}`}})
49
50
  }
50
51
  }
51
52
 
@@ -58,9 +59,10 @@ class test4 {
58
59
 
59
60
  custom_function(callback) {
60
61
  let msg = `custom func problem here id(${this.id})`
61
- console.log(`processing test4`.cyan)
62
- //callback({error: {msg: msg}}) //this will show errors
63
- callback() //this will show no errors
62
+ setTimeout(() => {
63
+ // callback({error: {msg: msg}}) //this will show errors
64
+ callback({success: {msg: `processing all (${this.id})}`}}) //this will show no errors
65
+ }, 3000)
64
66
  }
65
67
  }
66
68
  let tst4 = new test4()
@@ -69,9 +71,9 @@ let qObj = new queue(), props = { appender: 'sync_all' }
69
71
  qObj.load(props).add(new test1()).add(new test2()).add(new test3()).add(tst4.custom_function)
70
72
 
71
73
  qObj.process().then(res => {
72
- console.log(`done with all sync processing: (${res})`.bold.italic.blue)
74
+ console.log(`success with all sync processing: (${JSON.stringify(res)})`.bold.italic.green)
73
75
  }, err => {
74
- console.log(`errors with all sync processing: (${err})`.red)
76
+ console.log(`errors with all sync processing: (${JSON.stringify(err)})`.red)
75
77
  })
76
78
 
77
79
 
package/test_top_one.js CHANGED
@@ -4,29 +4,27 @@ var queue = require("./app.js");
4
4
 
5
5
  class test1 {
6
6
  process(callback){
7
- console.log(`processing test1`.cyan)
8
- callback()
7
+ callback({success: {msg: `processing test1`}})
9
8
  }
10
9
  }
11
10
 
12
11
  class test2 {
13
12
  process(callback){
14
- console.log(`processing test2`.cyan)
15
- callback()
13
+ callback({success: {msg: `processing test2`}})
16
14
  }
17
15
  }
18
16
 
19
17
  class test3 {
20
18
  process(callback){
21
- console.log(`processing test3`.cyan)
22
- callback()
19
+ callback({success: {msg: `processing test3`}})
23
20
  }
24
21
  }
25
22
 
26
23
  let qObj = new queue(), props = { appender: 'top_one', stats: true}
27
24
 
28
25
  qObj.load(props).add(new test1()).add(new test2(qObj)).add(new test3()).process({}).then(res => {
29
- console.log(res)
26
+ console.log(`success with all sync processing: (${JSON.stringify(res)})`.bold.italic.green)
30
27
  }, err => {
31
- console.log(`errors with top item processing: (${err})`.red)
28
+ console.log(`errors with all sync processing: (${JSON.stringify(err)})`.red)
32
29
  })
30
+
package/test_version.js CHANGED
@@ -17,10 +17,7 @@ class test1 {
17
17
  }
18
18
 
19
19
  process(callback) {
20
- let t = this
21
- console.log(`processing test1 version(${t.version})`.cyan)
22
- this.status = "done"
23
- callback()
20
+ callback({success: {msg: `processing test1 id(${this.id}) version(${this.version})`}})
24
21
  }
25
22
  }
26
23
 
@@ -34,10 +31,7 @@ class test2 {
34
31
  }
35
32
 
36
33
  process(callback) {
37
- let t = this, msg = `some kinda error is detected here`
38
- console.log(`processing test2 version(${t.version})`.cyan)
39
- // callback({error: {msg: msg}}) //this will show errors
40
- callback() //this will have no errors
34
+ callback({success: {msg: `processing test2 id(${this.id}) version(${this.version})`}})
41
35
  }
42
36
 
43
37
  ping() {
@@ -55,10 +49,7 @@ class test3 {
55
49
  }
56
50
 
57
51
  process(callback) {
58
- let t = this
59
- console.log(`processing test3 version(${t.version})`.cyan)
60
- console.log(`some async process`)
61
- callback()
52
+ callback({success: {msg: `processing test3 id(${this.id}) version(${this.version})`}})
62
53
  }
63
54
  }
64
55
 
@@ -72,9 +63,7 @@ class test4 {
72
63
  }
73
64
 
74
65
  process(callback) {
75
- let t = this
76
- console.log(`processing test4 version(${t.version})`.cyan)
77
- callback()
66
+ callback({success: {msg: `processing test4 id(${this.id}) version(${this.version})`}})
78
67
  }
79
68
  }
80
69
 
@@ -88,35 +77,21 @@ class test5 {
88
77
  }
89
78
 
90
79
  process(callback) {
91
- let t = this
92
- console.log(`processing test5 version(${t.version})`.cyan)
93
- callback()
80
+ callback({success: {msg: `processing test5 id(${this.id}) version(${this.version})`}})
94
81
  }
95
82
  }
96
83
  let qObj = new queue(), props = { appender: 'version' }
97
84
 
98
85
  qObj.load(props).add(new test1()).add(new test2()).add(new test3()).add(new test4()).add(new test5())
99
86
 
100
- qObj.await({ version: ['dev', 'test'] }).then(res => {
101
- console.log(`1) done with version['dev', 'test']: (${res})`.green)
87
+ qObj.process({ property: 'version', items: ['dev', 'test'] }).then(res => {
88
+ console.log(`success with status processing: (${JSON.stringify(res)})`.bold.italic.green)
102
89
  }, err => {
103
- console.log(`1) error['dev', 'test']: (${err})`.red)
90
+ console.log(`errors with status processing: (${JSON.stringify(err)})`.red)
104
91
  })
105
92
 
106
- qObj.await({ version: ['prod'] }).then(res => {
107
- console.log(`2) done with version['prod']: (${res})`.green)
108
- }, err => {
109
- console.log(`2) error['prod']: (${err})`.red)
110
- })
111
-
112
- qObj.await({ version: ['v1234'] }).then(res => {
113
- console.log(`3) done with version['v1234']: (${res})`.green)
114
- }, err => {
115
- console.log(`3) error['v1234']: (${err})`.red)
116
- })
117
-
118
- qObj.process().then(res => {
119
- console.log(`4) done with version synchronous processing: (${res})`.bold.italic.blue)
120
- }, err => {
121
- console.log(`4) errors with version synchronous processing: (${err})`.red)
122
- })
93
+ // qObj.process({ property: 'version', items: ['v1234'] }).then(res => {
94
+ // console.log(`4) done with version synchronous processing: (${res})`.bold.italic.green)
95
+ // }, err => {
96
+ // console.log(`4) errors with version synchronous processing: (${err})`.red)
97
+ // })