Skip to content
This repository has been archived by the owner on Jul 27, 2021. It is now read-only.

Commit

Permalink
Cleanup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tinchoz49 committed May 20, 2020
1 parent 79d2918 commit f9876a1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"multi-read-stream": "^2.0.0",
"mutexify": "^1.2.0",
"nanoresource-promise": "^2.0.0-beta.0",
"p-event": "^4.1.0",
"p-timeout": "^3.2.0",
"pify": "^5.0.0",
"pump": "^3.0.0",
Expand Down
25 changes: 16 additions & 9 deletions src/feed-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import hypertrie from 'hypertrie';
import jsonBuffer from 'buffer-json-encoding';
import defaultHypercore from 'hypercore';
import nanoresource from 'nanoresource-promise';
import pEvent from 'p-event';

import FeedDescriptor from './feed-descriptor';
import IndexDB from './index-db';
Expand Down Expand Up @@ -158,9 +159,13 @@ export class FeedStore extends EventEmitter {
return;
}

return new Promise((resolve) => {
this.once('ready', resolve);
});
try {
await pEvent(this, 'opened', {
rejectionEvents: ['closed']
});
} catch (err) {
throw new Error('FeedStore closed');
}
}

/**
Expand Down Expand Up @@ -398,6 +403,9 @@ export class FeedStore extends EventEmitter {
this._createDescriptor(path, options);
});

this.emit('opened');

// backward compatibility
this.emit('ready');
}

Expand Down Expand Up @@ -513,16 +521,15 @@ export class FeedStore extends EventEmitter {
}

async _isOpen () {
if (this.opened) {
return;
if ((!this.opening && !this.opened) || this.closing || this.closed) {
throw new Error('FeedStore closed');
}

// If is opening we wait to be ready.
if (this.opening) {
return this.ready();
if (this.opened) {
return;
}

throw new Error('FeedStore closed');
return this.ready();
}

/**
Expand Down
14 changes: 14 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4189,6 +4189,13 @@ p-each-series@^1.0.0:
dependencies:
p-reduce "^1.0.0"

p-event@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/p-event/-/p-event-4.1.0.tgz#e92bb866d7e8e5b732293b1c8269d38e9982bf8e"
integrity sha512-4vAd06GCsgflX4wHN1JqrMzBh/8QZ4j+rzp0cd2scXRwuBEv+QR3wrVA5aLhWDLw4y2WgDKvzWF3CCLmVM1UgA==
dependencies:
p-timeout "^2.0.1"

p-finally@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/p-finally/-/p-finally-1.0.0.tgz#3fbcfb15b899a44123b34b6dcc18b724336a2cae"
Expand Down Expand Up @@ -4241,6 +4248,13 @@ p-reduce@^1.0.0:
resolved "https://registry.yarnpkg.com/p-reduce/-/p-reduce-1.0.0.tgz#18c2b0dd936a4690a529f8231f58a0fdb6a47dfa"
integrity sha1-GMKw3ZNqRpClKfgjH1ig/bakffo=

p-timeout@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/p-timeout/-/p-timeout-2.0.1.tgz#d8dd1979595d2dc0139e1fe46b8b646cb3cdf038"
integrity sha512-88em58dDVB/KzPEx1X0N3LwFfYZPyDc4B6eF38M1rk9VTZMbxXXgjugz8mmwpS9Ox4BDZ+t6t3QP5+/gazweIA==
dependencies:
p-finally "^1.0.0"

p-timeout@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/p-timeout/-/p-timeout-3.2.0.tgz#c7e17abc971d2a7962ef83626b35d635acf23dfe"
Expand Down

0 comments on commit f9876a1

Please sign in to comment.