-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Open
Labels
enhancementNew feature or improvement.New feature or improvement.
Description
Hi @ricmoo,
I'm using WebSocketProvider server-side to listen to blockchain events and performing calls to smart contracts.
Sometimes the websocket pipe got broken and I need to reconnect it.
I use this code to detect ws close and reconnect but it would be nice to not have to rely on _websocket
to do it:
let wsProvider;
init = async () => {
wsProvider = new ethers.providers.WebSocketProvider(wsHost);
wsProvider._websocket.on('close', async (code) => {
console.log('ws closed', code);
wsProvider._websocket.terminate();
await sleep(3000); // wait before reconnect
init();
});
wsProvider.on('block', doStuff);
};
I also noticed when the websocket is broken Promise call don't reject wich is not super intuitive.
cruzdanilo, abunsen, ivopaunov, peterjah, undfined and 28 moreabunsen and edwardchew97T-Damer
Metadata
Metadata
Assignees
Labels
enhancementNew feature or improvement.New feature or improvement.