@leofcoin/workers 1.2.1 → 1.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/workers",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "",
5
5
  "module": "src/workers.js",
6
6
  "scripts": {
@@ -110,33 +110,31 @@ const _init = async ({ contracts, blocks, peerid })=> {
110
110
  }))
111
111
 
112
112
  const _worker = await new EasyWorker(join(__dirname, './block-worker.js'), {serialization: 'advanced', type: 'module' })
113
- // worker.on('message')
114
- _worker.once('message', async (blocks) => {
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)
119
-
120
- await execute(to, method, params)
121
- }))
122
- }
123
- let lastBlock
124
- if (blocks.length > 0) {
125
- lastBlock = blocks[blocks.length - 1].decoded
126
-
127
- lastBlock = await new BlockMessage(lastBlock)
128
- lastBlock = {
129
- ...lastBlock.decoded,
130
- hash: await lastBlock.hash
131
- }
132
- }
133
- worker.postMessage({type: 'machine-ready', lastBlock })
134
- _worker.terminate()
135
-
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);
119
+
120
+ await execute(to, method, params);
121
+ }));
122
+ }
136
123
 
137
-
138
- })
139
- worker.postMessage(blocks)
124
+ let lastBlock;
125
+ if (blocks.length > 0) {
126
+ lastBlock = blocks[blocks.length - 1].decoded;
127
+ lastBlock = await new BlockMessage(lastBlock);
128
+
129
+ lastBlock = {
130
+ ...lastBlock.decoded,
131
+ hash: await lastBlock.hash
132
+ };
133
+ }
134
+ worker.postMessage({type: 'machine-ready', lastBlock });
135
+ _worker.terminate();
136
+
137
+ worker.postMessage(blocks);
140
138
  }
141
139
 
142
140
  const tasks = async (e) => {