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: support timeout in rpc #432

Merged
merged 2 commits into from
Sep 28, 2022
Merged

Conversation

zhangyouxin
Copy link
Contributor

@zhangyouxin zhangyouxin commented Sep 27, 2022

Description

Currently there is no timeout for the lumos rpc methods:

import { RPC } from '@ckb-lumos/rpc'
const rpc = new RPC('YOUR RPC URL')
// if there is something wrong with network or rpc server causing it stuck
// the rpc requests will never return 
await rpc.getBlock("0x1")

This pr fixes this by adding a defaut timeout(30 seconds) to the rpc methods and provides a parameter on RPC constructor which user can customize timeout configuration:

import { RPC } from '@ckb-lumos/rpc'
const rpc = new RPC('YOUR RPC URL', { timeout: 1 }) // milliseconds

// throws time exceeded error
await rpc.getBlock("0x1")

Type of change

  • Refactor (non-breaking change)

How Has This Been Tested?

  • An example is provided to test this feature.
  • Added test cases

@vercel
Copy link

vercel bot commented Sep 27, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
lumos-website ✅ Ready (Inspect) Visit Preview Sep 28, 2022 at 3:32AM (UTC)

@codecov
Copy link

codecov bot commented Sep 27, 2022

Codecov Report

Merging #432 (f7a472b) into develop (064c601) will increase coverage by 0.00%.
The diff coverage is 95.23%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop     #432   +/-   ##
========================================
  Coverage    82.28%   82.28%           
========================================
  Files           95       95           
  Lines        19701    19717   +16     
  Branches      1863     1861    -2     
========================================
+ Hits         16210    16225   +15     
- Misses        3437     3438    +1     
  Partials        54       54           
Impacted Files Coverage Δ
packages/rpc/src/index.ts 72.67% <90.90%> (+0.55%) ⬆️
packages/rpc/src/method.ts 97.59% <100.00%> (+0.29%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 064c601...f7a472b. Read the comment docs.

Copy link
Collaborator

@homura homura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@homura homura merged commit 6444501 into ckb-js:develop Sep 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants