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 index in imap #159

Closed
latot opened this issue Dec 28, 2022 · 3 comments · Fixed by #160
Closed

Add index in imap #159

latot opened this issue Dec 28, 2022 · 3 comments · Fixed by #160

Comments

@latot
Copy link

latot commented Dec 28, 2022

Hi!, thx for this lib!, I was looking long time ago how to do this in a fast way.

The actual imap function does not keep the order of map, is not necessary bad, but I think would be great if it can return the index.
At least in my case, the data usually need more things than the request it self, and the index help to identify and relate information.

Thx!

@spyoungtech
Copy link
Owner

Yeah, I can see the usefulness of the ability to enumerate the responses with the original indices of the request.

Should be easy to implement...

@spyoungtech
Copy link
Owner

#160 proposed a new function for this purpose.

usage:

>>> rs = [grequests.get(f'https://httpbin.org/status/{code}') for code in range(200, 206)]
>>> for index, response in grequests.imap_enumerated(rs, size=5):
...     print(index, response)
1 <Response [201]>
0 <Response [200]>
4 <Response [204]>
2 <Response [202]>
5 <Response [205]>
3 <Response [203]>

@latot
Copy link
Author

latot commented Dec 29, 2022

:O Great!

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

Successfully merging a pull request may close this issue.

2 participants