Fix profile loader

This commit is contained in:
2022-12-27 12:33:52 +00:00
parent ff9de60b6b
commit f42e183bc8
5 changed files with 44 additions and 22 deletions

View File

@ -56,7 +56,7 @@ export default class Connection {
*/
AddSubscription(sub) {
let req = ["REQ", sub.Id, sub.ToObject()];
if(sub.OrSubs.length > 0) {
if (sub.OrSubs.length > 0) {
req = [
...req,
...sub.OrSubs.map(o => o.ToObject())
@ -71,9 +71,13 @@ export default class Connection {
* @param {any} subId Subscription id to remove
*/
RemoveSubscription(subId) {
let req = ["CLOSE", subId];
this._SendJson(req);
delete this.Subscriptions[subId];
if (this.Subscriptions[subId]) {
let req = ["CLOSE", subId];
this._SendJson(req);
delete this.Subscriptions[subId];
return true;
}
return false;
}
_SendJson(obj) {

View File

@ -60,7 +60,8 @@ export class NostrSystem {
};
sub.OnEnd = (c) => {
c.RemoveSubscription(sub.Id);
if(--counter === 0) {
console.debug(counter);
if (counter-- <= 0) {
resolve(events);
}
};
@ -68,6 +69,15 @@ export class NostrSystem {
s.AddSubscription(sub);
counter++;
}
// force timeout returning current results
setTimeout(() => {
for (let s of Object.values(this.Sockets)) {
s.RemoveSubscription(sub.Id);
counter++;
}
resolve(events);
}, 10_000);
});
}
}