aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/src/order_watcher/expiration_watcher.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/0x.js/src/order_watcher/expiration_watcher.ts')
-rw-r--r--packages/0x.js/src/order_watcher/expiration_watcher.ts19
1 files changed, 13 insertions, 6 deletions
diff --git a/packages/0x.js/src/order_watcher/expiration_watcher.ts b/packages/0x.js/src/order_watcher/expiration_watcher.ts
index cf0222e3c..71199e75f 100644
--- a/packages/0x.js/src/order_watcher/expiration_watcher.ts
+++ b/packages/0x.js/src/order_watcher/expiration_watcher.ts
@@ -6,6 +6,7 @@ import {SignedOrder, ZeroExError} from '../types';
import {Heap} from '../utils/heap';
import {ZeroEx} from '../0x';
+const DEFAULT_EXPIRATION_MARGIN_MS = 0;
const DEFAULT_ORDER_EXPIRATION_CHECKING_INTERVAL_MS = 50;
/**
@@ -17,9 +18,13 @@ export class ExpirationWatcher {
private expiration: {[orderHash: string]: BigNumber} = {};
private callbackIfExists?: (orderHash: string) => void;
private orderExpirationCheckingIntervalMs: number;
+ private expirationMarginMs: number;
private orderExpirationCheckingIntervalIdIfExists?: NodeJS.Timer;
- constructor(orderExpirationCheckingIntervalMsIfExists?: number) {
- this.orderExpirationCheckingIntervalMs = orderExpirationCheckingIntervalMsIfExists ||
+ constructor(expirationMarginIfExistsMs?: number,
+ orderExpirationCheckingIntervalIfExistsMs?: number) {
+ this.expirationMarginMs = expirationMarginIfExistsMs ||
+ DEFAULT_ORDER_EXPIRATION_CHECKING_INTERVAL_MS;
+ this.orderExpirationCheckingIntervalMs = expirationMarginIfExistsMs ||
DEFAULT_ORDER_EXPIRATION_CHECKING_INTERVAL_MS;
const scoreFunction = (orderHash: string) => this.expiration[orderHash].toNumber();
this.orderHashHeapByExpiration = new Heap(scoreFunction);
@@ -41,17 +46,19 @@ export class ExpirationWatcher {
delete this.callbackIfExists;
delete this.orderExpirationCheckingIntervalIdIfExists;
}
- public addOrder(orderHash: string, expirationUnixTimestampSec: BigNumber): void {
- this.expiration[orderHash] = expirationUnixTimestampSec;
+ public addOrder(orderHash: string, expirationUnixTimestampMs: BigNumber): void {
+ this.expiration[orderHash] = expirationUnixTimestampMs;
// We don't remove hashes from the heap on order remove because it's slow (linear).
// We just skip them later if the order was already removed from the order watcher.
this.orderHashHeapByExpiration.push(orderHash);
}
private pruneExpiredOrders(): void {
- const currentUnixTimestampSec = utils.getCurrentUnixTimestamp();
+ const currentUnixTimestampMs = utils.getCurrentUnixTimestampMs();
while (
this.orderHashHeapByExpiration.size() !== 0 &&
- this.expiration[this.orderHashHeapByExpiration.head()].lessThan(currentUnixTimestampSec) &&
+ this.expiration[this.orderHashHeapByExpiration.head()].lessThan(
+ currentUnixTimestampMs.plus(this.expirationMarginMs),
+ ) &&
!_.isUndefined(this.callbackIfExists)
) {
const orderHash = this.orderHashHeapByExpiration.pop();