Rename the ‘fn’ input to ‘handler’
- ID
002ce37- date
2023-04-14 22:59:34+00:00- author
Alex Chan <alex@alexwlchan.net>- parent
c3d46bf- message
Rename the 'fn' input to 'handler'- changed files
3 files, 12 additions, 12 deletions
Changed files
README.md (1419) → README.md (1424)
diff --git a/README.md b/README.md
index c69bd1d..8b9abf4 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,7 @@ It allows me to write code like:
```python
from concurrently import concurrently
-for (input, output) in concurrently(fn=perform, inputs=get_tasks_to_do()):
+for (input, output) in concurrently(handler=perform, inputs=get_tasks_to_do()):
print(input, output)
```
concurrently.py (1282) → concurrently.py (1327)
diff --git a/concurrently.py b/concurrently.py
index 39ea4f2..1c371e6 100644
--- a/concurrently.py
+++ b/concurrently.py
@@ -2,14 +2,14 @@ import concurrent.futures
import itertools
-def concurrently(fn, inputs, *, max_concurrency=5):
+def concurrently(handler, inputs, *, max_concurrency=5):
"""
- Calls the function ``fn`` on the values ``inputs``.
+ Calls the function ``handler`` on the values ``inputs``.
- ``fn`` should be a function that takes a single input, which is the
+ ``handler`` should be a function that takes a single input, which is the
individual values in the iterable ``inputs``.
- Generates (input, output) tuples as the calls to ``fn`` complete.
+ Generates (input, output) tuples as the calls to ``handler`` complete.
See https://alexwlchan.net/2019/10/adventures-with-concurrent-futures/ for an explanation
of how this function works.
@@ -17,12 +17,12 @@ def concurrently(fn, inputs, *, max_concurrency=5):
"""
# Make sure we get a consistent iterator throughout, rather than
# getting the first element repeatedly.
- fn_inputs = iter(inputs)
+ handler_inputs = iter(inputs)
with concurrent.futures.ThreadPoolExecutor() as executor:
futures = {
- executor.submit(fn, input): input
- for input in itertools.islice(fn_inputs, max_concurrency)
+ executor.submit(handler, input): input
+ for input in itertools.islice(handler_inputs, max_concurrency)
}
while futures:
@@ -34,6 +34,6 @@ def concurrently(fn, inputs, *, max_concurrency=5):
original_input = futures.pop(fut)
yield original_input, fut.result()
- for input in itertools.islice(fn_inputs, len(done)):
- fut = executor.submit(fn, input)
+ for input in itertools.islice(handler_inputs, len(done)):
+ fut = executor.submit(handler, input)
futures[fut] = input
test_concurrently.py (604) → test_concurrently.py (620)
diff --git a/test_concurrently.py b/test_concurrently.py
index 391a2a3..81f5cb3 100644
--- a/test_concurrently.py
+++ b/test_concurrently.py
@@ -10,7 +10,7 @@ def double(x):
def test_handles_iterator():
- result = set(concurrently(double, inputs=range(10)))
+ result = set(concurrently(handler=double, inputs=range(10)))
assert result == {
(0, 0),
@@ -27,6 +27,6 @@ def test_handles_iterator():
def test_handles_list():
- result = set(concurrently(double, inputs=[1, 3, 5, 7, 9, 11, 13]))
+ result = set(concurrently(handler=double, inputs=[1, 3, 5, 7, 9, 11, 13]))
assert result == {(1, 2), (3, 6), (5, 10), (7, 14), (9, 18), (11, 22), (13, 26)}