Changed getWatchedOrders to getStats and returns Stats object
This commit is contained in:
parent
9171f9ec60
commit
2e1222556f
@ -3,7 +3,7 @@
|
|||||||
"version": "2.1.2",
|
"version": "2.1.2",
|
||||||
"changes": [
|
"changes": [
|
||||||
{
|
{
|
||||||
"note": "Added getWatchCounts function"
|
"note": "Added getStats function and returns a Stats object"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"timestamp": 1538836030
|
"timestamp": 1538836030
|
||||||
|
@ -57,6 +57,10 @@ interface OrderStateByOrderHash {
|
|||||||
[orderHash: string]: OrderState;
|
[orderHash: string]: OrderState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface Stats {
|
||||||
|
orderCount: number;
|
||||||
|
}
|
||||||
|
|
||||||
const DEFAULT_ORDER_WATCHER_CONFIG: OrderWatcherConfig = {
|
const DEFAULT_ORDER_WATCHER_CONFIG: OrderWatcherConfig = {
|
||||||
orderExpirationCheckingIntervalMs: 50,
|
orderExpirationCheckingIntervalMs: 50,
|
||||||
eventPollingIntervalMs: 200,
|
eventPollingIntervalMs: 200,
|
||||||
@ -214,10 +218,12 @@ export class OrderWatcher {
|
|||||||
intervalUtils.clearAsyncExcludingInterval(this._cleanupJobIntervalIdIfExists);
|
intervalUtils.clearAsyncExcludingInterval(this._cleanupJobIntervalIdIfExists);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Gets number of orderHashes currently being watched by the order watcher instance.
|
* Gets statistics of the OrderWatcher Instance.
|
||||||
*/
|
*/
|
||||||
public getWatchCount(): number {
|
public getStats(): Stats {
|
||||||
return _.size(this._orderByOrderHash);
|
return {
|
||||||
|
orderCount : _.size(this._orderByOrderHash),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
private async _cleanupAsync(): Promise<void> {
|
private async _cleanupAsync(): Promise<void> {
|
||||||
for (const orderHash of _.keys(this._orderByOrderHash)) {
|
for (const orderHash of _.keys(this._orderByOrderHash)) {
|
||||||
|
@ -140,8 +140,8 @@ describe('OrderWatcher', () => {
|
|||||||
expect(() => orderWatcher.subscribe(_.noop.bind(_))).to.throw(OrderWatcherError.SubscriptionAlreadyPresent);
|
expect(() => orderWatcher.subscribe(_.noop.bind(_))).to.throw(OrderWatcherError.SubscriptionAlreadyPresent);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('#getWatchCount', async () => {
|
describe('#getStats', async () => {
|
||||||
it('should increment and decrement order counts', async () => {
|
it('orderCount should increment and decrement with order additions and removals', async () => {
|
||||||
signedOrder = await fillScenarios.createFillableSignedOrderAsync(
|
signedOrder = await fillScenarios.createFillableSignedOrderAsync(
|
||||||
makerAssetData,
|
makerAssetData,
|
||||||
takerAssetData,
|
takerAssetData,
|
||||||
@ -150,11 +150,11 @@ describe('OrderWatcher', () => {
|
|||||||
fillableAmount,
|
fillableAmount,
|
||||||
);
|
);
|
||||||
const orderHash = orderHashUtils.getOrderHashHex(signedOrder);
|
const orderHash = orderHashUtils.getOrderHashHex(signedOrder);
|
||||||
expect(orderWatcher.getWatchCount()).to.be.eq(0);
|
expect(orderWatcher.getStats().orderCount).to.be.eq(0);
|
||||||
await orderWatcher.addOrderAsync(signedOrder);
|
await orderWatcher.addOrderAsync(signedOrder);
|
||||||
expect(orderWatcher.getWatchCount()).to.be.eq(1);
|
expect(orderWatcher.getStats().orderCount).to.be.eq(1);
|
||||||
orderWatcher.removeOrder(orderHash);
|
orderWatcher.removeOrder(orderHash);
|
||||||
expect(orderWatcher.getWatchCount()).to.be.eq(0);
|
expect(orderWatcher.getStats().orderCount).to.be.eq(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('tests with cleanup', async () => {
|
describe('tests with cleanup', async () => {
|
||||||
|
@ -598,4 +598,4 @@ export interface Metadata {
|
|||||||
exportPathOrder: string[];
|
exportPathOrder: string[];
|
||||||
externalTypeToLink: ExternalTypeToLink;
|
externalTypeToLink: ExternalTypeToLink;
|
||||||
externalExportToLink: ExternalExportToLink;
|
externalExportToLink: ExternalExportToLink;
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user