@peerbit/program
Advanced tools
Comparing version 2.3.2 to 2.4.0
@@ -10,8 +10,11 @@ import PQueue from "p-queue"; | ||
this.properties = properties; | ||
this._openQueue = new PQueue({ concurrency: 1 }); | ||
this._openQueue = new Map(); | ||
this.items = new Map(); | ||
} | ||
async stop() { | ||
await Promise.all([...this._openQueue.values()].map((x) => { | ||
x.clear(); | ||
return x.onIdle(); | ||
})); | ||
this._openQueue.clear(); | ||
await this._openQueue.onIdle(); | ||
// Close all open databases | ||
@@ -24,2 +27,3 @@ await Promise.all([...this.items.values()].map((program) => program.close())); | ||
this.items.delete(program.address.toString()); | ||
// TODO remove item from this._openQueue? | ||
} | ||
@@ -74,2 +78,5 @@ async _onProgramOpen(program, mergeSrategy) { | ||
if (!this.properties.shouldMonitor(program)) { | ||
if (!program) { | ||
throw new Error("Failed to resolve program with address: " + storeOrAddress); | ||
} | ||
throw new Error(`Failed to open program because program is of type ${program?.constructor.name} `); | ||
@@ -97,2 +104,3 @@ } | ||
logger.debug(`Open database '${program.constructor.name}`); | ||
// TODO prevent resave if already saved | ||
const address = await program.save(this.properties.client.services.blocks); | ||
@@ -134,5 +142,25 @@ const existing = await this.checkProcessExisting(address, program, options?.existing); | ||
} | ||
return this._openQueue.add(fn); // TODO p-queue seem to return void type ; | ||
let address; | ||
if (typeof storeOrAddress === "string") { | ||
address = storeOrAddress; | ||
} | ||
else { | ||
if (storeOrAddress.closed) { | ||
address = await storeOrAddress.save(this.properties.client.services.blocks); | ||
} | ||
else { | ||
address = storeOrAddress.address; | ||
} | ||
} | ||
if (address) { | ||
let queue = this._openQueue.get(address); | ||
if (!queue) { | ||
queue = new PQueue({ concurrency: 1 }); | ||
this._openQueue.set(address, queue); | ||
} | ||
return queue.add(fn); // TODO p-queue seem to return void type ; | ||
} | ||
return fn(); // No address lookup, | ||
} | ||
} | ||
//# sourceMappingURL=handler.js.map |
{ | ||
"name": "@peerbit/program", | ||
"version": "2.3.2", | ||
"version": "2.4.0", | ||
"description": "Program interface", | ||
@@ -32,9 +32,9 @@ "type": "module", | ||
"dependencies": { | ||
"@dao-xyz/borsh": "^5.1.7", | ||
"@peerbit/blocks-interface": "^1.1.2", | ||
"@peerbit/crypto": "1.0.9", | ||
"@dao-xyz/borsh": "^5.1.8", | ||
"@peerbit/blocks-interface": "^1.1.3", | ||
"@peerbit/crypto": "1.0.10", | ||
"@peerbit/lazy-level": "^1.2.1", | ||
"@peerbit/pubsub-interface": "^1.1.4" | ||
"@peerbit/pubsub-interface": "^1.1.5" | ||
}, | ||
"gitHead": "6263a10a6236346d1c45d02dc0bf18eed1dc2995" | ||
"gitHead": "851f1a4fdff94efd0f9331a43d6f8652e27e6d26" | ||
} |
@@ -65,3 +65,3 @@ import { Blocks } from "@peerbit/blocks-interface"; | ||
items: Map<string, T>; | ||
private _openQueue: PQueue; | ||
private _openQueue: Map<string, PQueue>; | ||
@@ -79,3 +79,3 @@ constructor( | ||
) { | ||
this._openQueue = new PQueue({ concurrency: 1 }); | ||
this._openQueue = new Map(); | ||
this.items = new Map(); | ||
@@ -85,4 +85,9 @@ } | ||
async stop() { | ||
await Promise.all( | ||
[...this._openQueue.values()].map((x) => { | ||
x.clear(); | ||
return x.onIdle(); | ||
}) | ||
); | ||
this._openQueue.clear(); | ||
await this._openQueue.onIdle(); | ||
@@ -100,2 +105,4 @@ // Close all open databases | ||
this.items.delete(program.address!.toString()); | ||
// TODO remove item from this._openQueue? | ||
} | ||
@@ -170,3 +177,9 @@ | ||
)) as S; // TODO fix typings | ||
if (!this.properties.shouldMonitor(program)) { | ||
if (!program) { | ||
throw new Error( | ||
"Failed to resolve program with address: " + storeOrAddress | ||
); | ||
} | ||
throw new Error( | ||
@@ -201,5 +214,8 @@ `Failed to open program because program is of type ${program?.constructor.name} ` | ||
logger.debug(`Open database '${program.constructor.name}`); | ||
// TODO prevent resave if already saved | ||
const address = await program.save( | ||
this.properties.client.services.blocks | ||
); | ||
const existing = await this.checkProcessExisting( | ||
@@ -248,4 +264,26 @@ address, | ||
} | ||
return this._openQueue.add(fn) as any as S; // TODO p-queue seem to return void type ; | ||
let address: string; | ||
if (typeof storeOrAddress === "string") { | ||
address = storeOrAddress; | ||
} else { | ||
if (storeOrAddress.closed) { | ||
address = await storeOrAddress.save( | ||
this.properties.client.services.blocks | ||
); | ||
} else { | ||
address = storeOrAddress.address; | ||
} | ||
} | ||
if (address) { | ||
let queue = this._openQueue.get(address); | ||
if (!queue) { | ||
queue = new PQueue({ concurrency: 1 }); | ||
this._openQueue.set(address, queue); | ||
} | ||
return queue.add(fn) as any as S; // TODO p-queue seem to return void type ; | ||
} | ||
return fn(); // No address lookup, | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
71496
1529
- Removed@peerbit/crypto@1.0.9(transitive)
Updated@dao-xyz/borsh@^5.1.8
Updated@peerbit/crypto@1.0.10