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

Add timeout for getPastEventsFrom #9

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

yymone
Copy link
Contributor

@yymone yymone commented Mar 23, 2022

add a function to add timeout functionality for call web3 api.

@yymone yymone requested a review from xgaozoyoe March 23, 2022 01:54
@yymone
Copy link
Contributor Author

yymone commented Mar 23, 2022

先就这样写了,这个东西同一个DelphinusContract
多线程多次调用没问题,但是整个Process如果有多个delphinusContract就会出问题。

因为SetTimeout的handler是一个Process的全局变量,但是不改接口没法把handler id定义在Monitor的main里。
不过现在monitor也只有一个delphinusContract. getPastEventsFrom()也只被monitor调用。

这块不知道有没有办法再不改接口的情况下能够一个process只存一套timeoutHandlerDict和timeOutId

@yymone
Copy link
Contributor Author

yymone commented Mar 23, 2022

不对,我放在了class的static里,理论上就是全局的了。。。。不过不知道javascript的实现是不是符合。

src/client.ts Outdated
});

// returns a race between timeout and the passed promise
return Promise.race<T>([promise, timeoutPromise]);
Copy link

Choose a reason for hiding this comment

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

suggested change:

return Promise.race([promise, timeoutPromise]).then({ (value) ==> clearTimeout(timeoutHandler)})

Copy link
Contributor Author

Choose a reason for hiding this comment

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

你说的很对,有方法可以弄好的。

@yymone
Copy link
Contributor Author

yymone commented Mar 23, 2022

已改完

@yymone yymone requested a review from igerry March 23, 2022 03:49

// returns a race between timeout and the passed promise
return Promise.race<T>([promise, timeoutPromise])
.then(
Copy link

Choose a reason for hiding this comment

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

perfect

src/client.ts Outdated Show resolved Hide resolved
@yymone yymone requested a review from igerry March 23, 2022 04:00
Copy link

@igerry igerry left a comment

Choose a reason for hiding this comment

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

LGTM (Looks good to me)

Copy link

@igerry igerry left a comment

Choose a reason for hiding this comment

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

LGTM

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