ws-client-events-decorators
v1.0.4
Published
Not a big extension for socket.io-client You can use promises to send events to the server and get the result.
Downloads
4
Readme
Not a big extension for socket.io-client You can use promises to send events to the server and get the result.
import {Socket} from 'socket.io-client';
import * as io from 'socket.io-client';
import {WsEvent} from 'ws-client-events-decorators';
export class OrdersService {
private socket: Socket;
@WsEvent({name: 'cancel order', error: 'error cancel order'})
public cancelOrder: (orderId: number) => Promise<void>;
@WsEvent({name: 'cancel order', success: 'success cancel order'})
public createOrder: (amount: number, price: number) => Promise<{orderId: number}>;
constructor() {
this.socket = io('localhost:4200');
}
}
(async () => {
const ordersService = new OrdersService();
const orderId = await ordersService.createOrder(3, 4);
try {
await ordersService.cancelOrder(orderId);
// SUCCESS !!!
} catch (e) {
// has a ERROR, resolve it
console.log(e.message);
}
})();
Issues: [email protected]