Skip to content

Commit

Permalink
Trader minor cleanups (coinbase#172)
Browse files Browse the repository at this point in the history
* Trader#cancelOrder: remove then block that only returns its input.

* Trader#handleCancelOrder: remove unclear return keyword.

Don't return the result of this.emitMessageAsync() because it doesn't
return anything.

* Remove unnecessary uses of Promise.resolve().

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then#Return_value
  • Loading branch information
blair authored and fb55 committed Apr 10, 2018
1 parent e2c3f2a commit 6530574
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/core/Trader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,14 @@ export class Trader extends Writable {
// We pass the message along, but let the user decide what to do
// We also have to wrap this call in a setImmediate; else any errors in the event handler will get thrown from here and lead to an unhandledRejection
this.emitMessageAsync('Trader.place-order-failed', err.asMessage());
return Promise.resolve(null);
return null;
});
}

cancelOrder(orderId: string): Promise<string> {
return this.api.cancelOrder(orderId).then((id: string) => {
// To avoid race conditions, we only actually remove the order when the tradeFinalized message arrives
return id;
});
// To avoid race conditions, we only actually remove the order
// when the tradeFinalized message arrives.
return this.api.cancelOrder(orderId);
}

cancelMyOrders(): Promise<string[]> {
Expand Down Expand Up @@ -165,8 +164,7 @@ export class Trader extends Writable {
actualOrders.forEach((order: LiveOrder) => {
book.add(order);
});
const diff = OrderbookDiff.compareByOrder(this.myBook, book);
return Promise.resolve(diff);
return OrderbookDiff.compareByOrder(this.myBook, book);
});
}

Expand Down Expand Up @@ -217,7 +215,7 @@ export class Trader extends Writable {

private handleCancelOrder(request: CancelOrderRequestMessage) {
this.cancelOrder(request.orderId).then((result: string) => {
return this.emitMessageAsync('Trader.order-cancelled', result);
this.emitMessageAsync('Trader.order-cancelled', result);
}, (err: Error) => {
this.emitMessageAsync('Trader.cancel-order-failed', err);
});
Expand Down

0 comments on commit 6530574

Please sign in to comment.