Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: refactor reconnect and support for renew subscription #71

Merged
merged 1 commit into from
May 9, 2022

Conversation

moraleinside
Copy link
Contributor

Update:
Refactor reconnect
Add ReconnectHandler, AlwaysReconnect and RenewSubscription connect handlers to support for different use cases.

Usage:
Use auto resubscribe with maximum 5 retries and 1000ms interval.

const ws = new WS_RPC(config.wsURL);
const provider = new ViteAPI(ws, () => {
  console.log("Connected");
}, new RenewSubscription(retryTimes = 5, retryInterval = 1000));

Use auto resubscribe with maximum retries and default (10000ms) interval.

const ws = new WS_RPC(config.wsURL);
const provider = new ViteAPI(ws, () => {
  console.log("Connected");
}, new RenewSubscription(Number.MAX_VALUE));

Use auto reconnect with unlimited retries (no resubscribe) and default (10000ms) interval.

const ws = new WS_RPC(config.wsURL);
const provider = new ViteAPI(ws, () => {
  console.log("Connected");
}, new AlwaysReconnect());

Use default handler (reconnect with 10 retries and 10000ms interval). Compatible with current code.

const ws = new WS_RPC(config.wsURL);
const provider = new ViteAPI(ws, () => {
  console.log("Connected");
});

Solved #55

Note: Extend ReconnectHandler or base ConnectHandler class if you need to implement your own handler.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 2227064899

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 86.701%

Totals Coverage Status
Change from base Build 2207178677: 0.0%
Covered Lines: 1354
Relevant Lines: 1483

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants