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

[Feature Request] Add a way to await "previous consumed tokens" #82

Open
yaquawa opened this issue Jun 1, 2021 · 0 comments
Open

[Feature Request] Add a way to await "previous consumed tokens" #82

yaquawa opened this issue Jun 1, 2021 · 0 comments

Comments

@yaquawa
Copy link

yaquawa commented Jun 1, 2021

Hi, thanks for your efforts to this lib.

I have a use case where I don't know the actually value of amount for giving to removeTokens method until I've sent the request(AWS DynamoDB in my case).

Here is the pseudo code to explain what I mean:

let previousConsumedTokens = 0

async function foo(){
  for(let i = 0; i<10 ; i++) {
     await bucket.removeTokens(previousConsumedTokens)
     previousConsumedTokens = await sendRequest()
  }
}

foo() // run only one time will work



// call `foo` multiple times may not work,
// because the `previousConsumedTokens` may not be the "real" previousConsumedTokens.
foo() 

So the API may looks like this:

async function foo(){
  for(let i = 0; i<10 ; i++) {
     await bucket.removePrevTokens()
     previousConsumedTokens = await sendRequest()
     bucket.addPrevTokens(previousConsumedTokens)
  }
}

if you are OK for this feature request, I can send a PR for this, what do you think?

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

No branches or pull requests

1 participant