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

Concurrency documentation #120

Closed
3 tasks done
gadicc opened this issue Apr 8, 2021 · 1 comment
Closed
3 tasks done

Concurrency documentation #120

gadicc opened this issue Apr 8, 2021 · 1 comment
Labels

Comments

@gadicc
Copy link
Owner

gadicc commented Apr 8, 2021

Originally posted by @gadicc in #114 (comment)

To get started (this will become part of the docs soon):

const symbols = ['TSLA', 'MSFT', 'AAPL'];

// Will perform one request at a time, one after the other
const data = [];
for (let symbol of symbols)
  data.push(await yahooFinance.quoteSummary(symbol));

// Will perform all requests simultaneously (not great for > ~8 symbols)
const data = Promise.all(symbols.map(symbol => yahooFinance.quoteSummary(symbol)));

Both approaches return an identical result, the only different is that the 2nd method performs all requests at the same time.

You can use something like p-limit to limit the number of simultaneous requests to something like 8 or whatever is appropriate for your network. I'm currently working on baking this in with #76, so you can watch that space. That will make it easier to limit the total concurrent calls across different functions or callbacks, which has the same convenience of quoteCombine - even though it will still be with multiple network requests. You can do it already without a limit but you might choke your connection if you do it with too many requests simultaneously.

Hope that all makes sense and let me know if you have any more questions. The code above is not tested but should be good 😅

@gadicc
Copy link
Owner Author

gadicc commented Jun 1, 2021

🎉 This issue has been resolved in version 1.11.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@gadicc gadicc added the released label Jun 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant