@leofcoin/workers 1.2.4 → 1.2.5

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.
@@ -142,29 +142,36 @@ const _init = async ({ contracts, blocks, peerid })=> {
142
142
  return contract
143
143
  }));
144
144
 
145
- const _worker = await new worker$1.EasyWorker(require$$1.join(__dirname, './block-worker.js'), {serialization: 'advanced', type: 'module' });
146
- blocks = await _worker.once(blocks);
147
-
148
- for (const block of blocks) {
149
- await Promise.all(block.decoded.transactions.map(async message => {
150
- const {from, to, method, params} = message;
151
- globalThis.msg = createMessage(from);
145
+ let lastBlock = {hash: '0x0'};
146
+
147
+ if (blocks?.length > 0) {
148
+ const _worker = await new worker$1.EasyWorker(require$$1.join(__dirname, './block-worker.js'), {serialization: 'advanced', type: 'module' });
149
+ blocks = await _worker.once(blocks);
150
+
151
+ for (const block of blocks) {
152
+ await Promise.all(block.decoded.transactions.map(async message => {
153
+ const {from, to, method, params} = message;
154
+ globalThis.msg = createMessage(from);
155
+
156
+ await execute(to, method, params);
157
+ }));
158
+ }
152
159
 
153
- await execute(to, method, params);
154
- }));
160
+ if (blocks.length > 0) {
161
+ lastBlock = blocks[blocks.length - 1].decoded;
162
+ lastBlock = await new utils.BlockMessage(lastBlock);
163
+
164
+ lastBlock = {
165
+ ...lastBlock.decoded,
166
+ hash: await lastBlock.hash
167
+ };
168
+ }
155
169
  }
156
170
 
157
- let lastBlock;
158
- if (blocks.length > 0) {
159
- lastBlock = blocks[blocks.length - 1].decoded;
160
- lastBlock = await new utils.BlockMessage(lastBlock);
171
+
161
172
 
162
- lastBlock = {
163
- ...lastBlock.decoded,
164
- hash: await lastBlock.hash
165
- };
166
- }
167
- worker.postMessage({type: 'machine-ready', lastBlock });
173
+
174
+ worker.postMessage({type: 'machine-ready', lastBlock});
168
175
  _worker.terminate();
169
176
 
170
177
  worker.postMessage(blocks);
@@ -172,14 +179,33 @@ const _init = async ({ contracts, blocks, peerid })=> {
172
179
 
173
180
  const tasks = async (e) => {
174
181
  const id = e.id;
175
- if (e.type === 'init') await _init(e.input);
182
+ if (e.type === 'init') {
183
+ try {
184
+ await _init(e.input);
185
+ } catch (e) {
186
+ worker.postMessage({
187
+ type: 'initError',
188
+ message: e.message,
189
+ id
190
+ });
191
+ }
192
+ }
176
193
  if (e.type === 'get') {
177
- const value = await get(e.input.contract, e.input.method, e.input.params);
178
- worker.postMessage({
179
- type: 'response',
180
- id,
181
- value
182
- });
194
+ try {
195
+ const value = await get(e.input.contract, e.input.method, e.input.params);
196
+ worker.postMessage({
197
+ type: 'response',
198
+ id,
199
+ value
200
+ });
201
+ } catch (e) {
202
+ worker.postMessage({
203
+ type: 'fetchError',
204
+ message: e.message,
205
+ id
206
+ });
207
+ }
208
+
183
209
  }
184
210
  if (e.type === 'execute') {
185
211
  try {
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- require('./machine-worker-237898fd.js');
3
+ require('./machine-worker-d1df2d67.js');
4
4
  require('./worker-6ace445f.js');
5
5
  require('./utils-6e881be4.js');
6
6
  require('path');
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var transactionWorker = require('./transaction-worker-176a5aaa.js');
6
6
  var blockWorker = require('./block-worker-21ad8152.js');
7
7
  var poolWorker = require('./pool-worker-f450eeff.js');
8
- var machineWorker = require('./machine-worker-237898fd.js');
8
+ var machineWorker = require('./machine-worker-d1df2d67.js');
9
9
  require('./worker-6ace445f.js');
10
10
  require('stream');
11
11
  require('events');
@@ -140,29 +140,36 @@ const _init = async ({ contracts, blocks, peerid })=> {
140
140
  return contract
141
141
  }));
142
142
 
143
- const _worker = await new EasyWorker(join(__dirname, './block-worker.js'), {serialization: 'advanced', type: 'module' });
144
- blocks = await _worker.once(blocks);
145
-
146
- for (const block of blocks) {
147
- await Promise.all(block.decoded.transactions.map(async message => {
148
- const {from, to, method, params} = message;
149
- globalThis.msg = createMessage(from);
143
+ let lastBlock = {hash: '0x0'};
144
+
145
+ if (blocks?.length > 0) {
146
+ const _worker = await new EasyWorker(join(__dirname, './block-worker.js'), {serialization: 'advanced', type: 'module' });
147
+ blocks = await _worker.once(blocks);
148
+
149
+ for (const block of blocks) {
150
+ await Promise.all(block.decoded.transactions.map(async message => {
151
+ const {from, to, method, params} = message;
152
+ globalThis.msg = createMessage(from);
153
+
154
+ await execute(to, method, params);
155
+ }));
156
+ }
150
157
 
151
- await execute(to, method, params);
152
- }));
158
+ if (blocks.length > 0) {
159
+ lastBlock = blocks[blocks.length - 1].decoded;
160
+ lastBlock = await new BlockMessage(lastBlock);
161
+
162
+ lastBlock = {
163
+ ...lastBlock.decoded,
164
+ hash: await lastBlock.hash
165
+ };
166
+ }
153
167
  }
154
168
 
155
- let lastBlock;
156
- if (blocks.length > 0) {
157
- lastBlock = blocks[blocks.length - 1].decoded;
158
- lastBlock = await new BlockMessage(lastBlock);
169
+
159
170
 
160
- lastBlock = {
161
- ...lastBlock.decoded,
162
- hash: await lastBlock.hash
163
- };
164
- }
165
- worker.postMessage({type: 'machine-ready', lastBlock });
171
+
172
+ worker.postMessage({type: 'machine-ready', lastBlock});
166
173
  _worker.terminate();
167
174
 
168
175
  worker.postMessage(blocks);
@@ -170,14 +177,33 @@ const _init = async ({ contracts, blocks, peerid })=> {
170
177
 
171
178
  const tasks = async (e) => {
172
179
  const id = e.id;
173
- if (e.type === 'init') await _init(e.input);
180
+ if (e.type === 'init') {
181
+ try {
182
+ await _init(e.input);
183
+ } catch (e) {
184
+ worker.postMessage({
185
+ type: 'initError',
186
+ message: e.message,
187
+ id
188
+ });
189
+ }
190
+ }
174
191
  if (e.type === 'get') {
175
- const value = await get(e.input.contract, e.input.method, e.input.params);
176
- worker.postMessage({
177
- type: 'response',
178
- id,
179
- value
180
- });
192
+ try {
193
+ const value = await get(e.input.contract, e.input.method, e.input.params);
194
+ worker.postMessage({
195
+ type: 'response',
196
+ id,
197
+ value
198
+ });
199
+ } catch (e) {
200
+ worker.postMessage({
201
+ type: 'fetchError',
202
+ message: e.message,
203
+ id
204
+ });
205
+ }
206
+
181
207
  }
182
208
  if (e.type === 'execute') {
183
209
  try {
@@ -1,4 +1,4 @@
1
- import './machine-worker-5740c3e5.js';
1
+ import './machine-worker-63056a0b.js';
2
2
  import './worker-def77c26.js';
3
3
  import './utils-ac8c68e6.js';
4
4
  import 'path';
@@ -1,7 +1,7 @@
1
1
  import { t as transactionWorker } from './transaction-worker-548cd200.js';
2
2
  import { b as blockWorker } from './block-worker-414860e0.js';
3
3
  import { p as poolWorker } from './pool-worker-0d927e3c.js';
4
- import { m as machineWorker } from './machine-worker-5740c3e5.js';
4
+ import { m as machineWorker } from './machine-worker-63056a0b.js';
5
5
  import './worker-def77c26.js';
6
6
  import 'stream';
7
7
  import 'events';
@@ -147,29 +147,36 @@ const _init = async ({ contracts, blocks, peerid })=> {
147
147
  return contract
148
148
  }));
149
149
 
150
- const _worker = await new EasyWorker__default["default"](path.join(__dirname, './block-worker.js'), {serialization: 'advanced', type: 'module' });
151
- blocks = await _worker.once(blocks);
152
-
153
- for (const block of blocks) {
154
- await Promise.all(block.decoded.transactions.map(async message => {
155
- const {from, to, method, params} = message;
156
- globalThis.msg = createMessage(from);
150
+ let lastBlock = {hash: '0x0'};
151
+
152
+ if (blocks?.length > 0) {
153
+ const _worker = await new EasyWorker__default["default"](path.join(__dirname, './block-worker.js'), {serialization: 'advanced', type: 'module' });
154
+ blocks = await _worker.once(blocks);
155
+
156
+ for (const block of blocks) {
157
+ await Promise.all(block.decoded.transactions.map(async message => {
158
+ const {from, to, method, params} = message;
159
+ globalThis.msg = createMessage(from);
160
+
161
+ await execute(to, method, params);
162
+ }));
163
+ }
157
164
 
158
- await execute(to, method, params);
159
- }));
165
+ if (blocks.length > 0) {
166
+ lastBlock = blocks[blocks.length - 1].decoded;
167
+ lastBlock = await new utils.BlockMessage(lastBlock);
168
+
169
+ lastBlock = {
170
+ ...lastBlock.decoded,
171
+ hash: await lastBlock.hash
172
+ };
173
+ }
160
174
  }
161
175
 
162
- let lastBlock;
163
- if (blocks.length > 0) {
164
- lastBlock = blocks[blocks.length - 1].decoded;
165
- lastBlock = await new utils.BlockMessage(lastBlock);
176
+
166
177
 
167
- lastBlock = {
168
- ...lastBlock.decoded,
169
- hash: await lastBlock.hash
170
- };
171
- }
172
- worker.postMessage({type: 'machine-ready', lastBlock });
178
+
179
+ worker.postMessage({type: 'machine-ready', lastBlock});
173
180
  _worker.terminate();
174
181
 
175
182
  worker.postMessage(blocks);
@@ -177,14 +184,33 @@ const _init = async ({ contracts, blocks, peerid })=> {
177
184
 
178
185
  const tasks = async (e) => {
179
186
  const id = e.id;
180
- if (e.type === 'init') await _init(e.input);
187
+ if (e.type === 'init') {
188
+ try {
189
+ await _init(e.input);
190
+ } catch (e) {
191
+ worker.postMessage({
192
+ type: 'initError',
193
+ message: e.message,
194
+ id
195
+ });
196
+ }
197
+ }
181
198
  if (e.type === 'get') {
182
- const value = await get(e.input.contract, e.input.method, e.input.params);
183
- worker.postMessage({
184
- type: 'response',
185
- id,
186
- value
187
- });
199
+ try {
200
+ const value = await get(e.input.contract, e.input.method, e.input.params);
201
+ worker.postMessage({
202
+ type: 'response',
203
+ id,
204
+ value
205
+ });
206
+ } catch (e) {
207
+ worker.postMessage({
208
+ type: 'fetchError',
209
+ message: e.message,
210
+ id
211
+ });
212
+ }
213
+
188
214
  }
189
215
  if (e.type === 'execute') {
190
216
  try {
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- require('./machine-worker-095c9ecb.js');
3
+ require('./machine-worker-13e601fc.js');
4
4
  require('@leofcoin/codec-format-interface');
5
5
  require('./utils-1dc37f72.js');
6
6
  require('path');
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var transactionWorker = require('./transaction-worker-8eecc7a1.js');
6
6
  var blockWorker = require('./block-worker-60e4cfa3.js');
7
7
  var poolWorker = require('./pool-worker-81e8b4c0.js');
8
- var machineWorker = require('./machine-worker-095c9ecb.js');
8
+ var machineWorker = require('./machine-worker-13e601fc.js');
9
9
  require('@leofcoin/codec-format-interface');
10
10
  require('./transaction-220a3a15.js');
11
11
  require('@vandeurenglenn/easy-worker');
@@ -141,29 +141,36 @@ const _init = async ({ contracts, blocks, peerid })=> {
141
141
  return contract
142
142
  }));
143
143
 
144
- const _worker = await new EasyWorker(join(__dirname, './block-worker.js'), {serialization: 'advanced', type: 'module' });
145
- blocks = await _worker.once(blocks);
146
-
147
- for (const block of blocks) {
148
- await Promise.all(block.decoded.transactions.map(async message => {
149
- const {from, to, method, params} = message;
150
- globalThis.msg = createMessage(from);
144
+ let lastBlock = {hash: '0x0'};
145
+
146
+ if (blocks?.length > 0) {
147
+ const _worker = await new EasyWorker(join(__dirname, './block-worker.js'), {serialization: 'advanced', type: 'module' });
148
+ blocks = await _worker.once(blocks);
149
+
150
+ for (const block of blocks) {
151
+ await Promise.all(block.decoded.transactions.map(async message => {
152
+ const {from, to, method, params} = message;
153
+ globalThis.msg = createMessage(from);
154
+
155
+ await execute(to, method, params);
156
+ }));
157
+ }
151
158
 
152
- await execute(to, method, params);
153
- }));
159
+ if (blocks.length > 0) {
160
+ lastBlock = blocks[blocks.length - 1].decoded;
161
+ lastBlock = await new BlockMessage(lastBlock);
162
+
163
+ lastBlock = {
164
+ ...lastBlock.decoded,
165
+ hash: await lastBlock.hash
166
+ };
167
+ }
154
168
  }
155
169
 
156
- let lastBlock;
157
- if (blocks.length > 0) {
158
- lastBlock = blocks[blocks.length - 1].decoded;
159
- lastBlock = await new BlockMessage(lastBlock);
170
+
160
171
 
161
- lastBlock = {
162
- ...lastBlock.decoded,
163
- hash: await lastBlock.hash
164
- };
165
- }
166
- worker.postMessage({type: 'machine-ready', lastBlock });
172
+
173
+ worker.postMessage({type: 'machine-ready', lastBlock});
167
174
  _worker.terminate();
168
175
 
169
176
  worker.postMessage(blocks);
@@ -171,14 +178,33 @@ const _init = async ({ contracts, blocks, peerid })=> {
171
178
 
172
179
  const tasks = async (e) => {
173
180
  const id = e.id;
174
- if (e.type === 'init') await _init(e.input);
181
+ if (e.type === 'init') {
182
+ try {
183
+ await _init(e.input);
184
+ } catch (e) {
185
+ worker.postMessage({
186
+ type: 'initError',
187
+ message: e.message,
188
+ id
189
+ });
190
+ }
191
+ }
175
192
  if (e.type === 'get') {
176
- const value = await get(e.input.contract, e.input.method, e.input.params);
177
- worker.postMessage({
178
- type: 'response',
179
- id,
180
- value
181
- });
193
+ try {
194
+ const value = await get(e.input.contract, e.input.method, e.input.params);
195
+ worker.postMessage({
196
+ type: 'response',
197
+ id,
198
+ value
199
+ });
200
+ } catch (e) {
201
+ worker.postMessage({
202
+ type: 'fetchError',
203
+ message: e.message,
204
+ id
205
+ });
206
+ }
207
+
182
208
  }
183
209
  if (e.type === 'execute') {
184
210
  try {
@@ -1,4 +1,4 @@
1
- import './machine-worker-9cbdae03.js';
1
+ import './machine-worker-3b7771c0.js';
2
2
  import '@leofcoin/codec-format-interface';
3
3
  import './utils-e87bc63d.js';
4
4
  import 'path';
@@ -1,7 +1,7 @@
1
1
  import { t as transactionWorker } from './transaction-worker-105deaa8.js';
2
2
  import { b as blockWorker } from './block-worker-f539b1b2.js';
3
3
  import { p as poolWorker } from './pool-worker-f65671d7.js';
4
- import { m as machineWorker } from './machine-worker-9cbdae03.js';
4
+ import { m as machineWorker } from './machine-worker-3b7771c0.js';
5
5
  import '@leofcoin/codec-format-interface';
6
6
  import './transaction-d06dc6c4.js';
7
7
  import '@vandeurenglenn/easy-worker';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/workers",
3
- "version": "1.2.4",
3
+ "version": "1.2.5",
4
4
  "description": "",
5
5
  "module": "src/workers.js",
6
6
  "scripts": {
@@ -109,29 +109,36 @@ const _init = async ({ contracts, blocks, peerid })=> {
109
109
  return contract
110
110
  }))
111
111
 
112
- const _worker = await new EasyWorker(join(__dirname, './block-worker.js'), {serialization: 'advanced', type: 'module' })
113
- blocks = await _worker.once(blocks)
114
-
115
- for (const block of blocks) {
116
- await Promise.all(block.decoded.transactions.map(async message => {
117
- const {from, to, method, params} = message;
118
- globalThis.msg = createMessage(from);
112
+ let lastBlock = {hash: '0x0'};
113
+
114
+ if (blocks?.length > 0) {
115
+ const _worker = await new EasyWorker(join(__dirname, './block-worker.js'), {serialization: 'advanced', type: 'module' })
116
+ blocks = await _worker.once(blocks)
117
+
118
+ for (const block of blocks) {
119
+ await Promise.all(block.decoded.transactions.map(async message => {
120
+ const {from, to, method, params} = message;
121
+ globalThis.msg = createMessage(from);
122
+
123
+ await execute(to, method, params);
124
+ }));
125
+ }
119
126
 
120
- await execute(to, method, params);
121
- }));
127
+ if (blocks.length > 0) {
128
+ lastBlock = blocks[blocks.length - 1].decoded;
129
+ lastBlock = await new BlockMessage(lastBlock);
130
+
131
+ lastBlock = {
132
+ ...lastBlock.decoded,
133
+ hash: await lastBlock.hash
134
+ };
135
+ }
122
136
  }
123
137
 
124
- let lastBlock;
125
- if (blocks.length > 0) {
126
- lastBlock = blocks[blocks.length - 1].decoded;
127
- lastBlock = await new BlockMessage(lastBlock);
138
+
128
139
 
129
- lastBlock = {
130
- ...lastBlock.decoded,
131
- hash: await lastBlock.hash
132
- };
133
- }
134
- worker.postMessage({type: 'machine-ready', lastBlock });
140
+
141
+ worker.postMessage({type: 'machine-ready', lastBlock});
135
142
  _worker.terminate();
136
143
 
137
144
  worker.postMessage(blocks);
@@ -139,14 +146,33 @@ const _init = async ({ contracts, blocks, peerid })=> {
139
146
 
140
147
  const tasks = async (e) => {
141
148
  const id = e.id
142
- if (e.type === 'init') await _init(e.input)
149
+ if (e.type === 'init') {
150
+ try {
151
+ await _init(e.input)
152
+ } catch (e) {
153
+ worker.postMessage({
154
+ type: 'initError',
155
+ message: e.message,
156
+ id
157
+ })
158
+ }
159
+ }
143
160
  if (e.type === 'get') {
144
- const value = await get(e.input.contract, e.input.method, e.input.params)
145
- worker.postMessage({
146
- type: 'response',
147
- id,
148
- value
149
- })
161
+ try {
162
+ const value = await get(e.input.contract, e.input.method, e.input.params)
163
+ worker.postMessage({
164
+ type: 'response',
165
+ id,
166
+ value
167
+ })
168
+ } catch (e) {
169
+ worker.postMessage({
170
+ type: 'fetchError',
171
+ message: e.message,
172
+ id
173
+ })
174
+ }
175
+
150
176
  }
151
177
  if (e.type === 'execute') {
152
178
  try {