Skip to content

Commit d35197a

Browse files
authored
rename awhile, afor to while-async, for-async (#1250)
Hi, can you please review patch to rename the `awhile` and `afor` macros to `while-async` and `for-async` for better clarity. It addresses the point about naming in #1248. I felt placing `async` after `for`/`while` reads more naturally, but I'm open to other suggestions if you think a better naming. Thanks Co-authored-by: ikappaki <[email protected]>
1 parent 8b6f29b commit d35197a

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
* Removed implicit support for single-use iterables in sequences, and introduced `iterator-seq` to expliciltly handle them (#1192)
1818
* `basilisp.core/str` now delegates to the builtin Python `str` in all cases except for customizing the string output for builtin Python types (#1237)
1919
* Optimised mainstream seq-consuming functions by coercing their inputs into `seq` upfront (#1234)
20+
* Renamed `awhile` and `afor` to `while-async` and `for-async` for improved clarity (#1248)
2021

2122
### Fixed
2223
* Fix a bug where protocols with methods with leading hyphens in the could not be defined (#1230)

src/basilisp/core.lpy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4120,13 +4120,13 @@
41204120
;; Async Macros ;;
41214121
;;;;;;;;;;;;;;;;;;
41224122

4123-
(defmacro afor
4123+
(defmacro for-async
41244124
"Repeatedly execute ``body`` while the binding name is repeatedly rebound to
41254125
successive values from the asynchronous iterable.
41264126

41274127
.. warning::
41284128

4129-
The ``afor`` macro may only be used in an asynchronous function context."
4129+
The ``for-async`` macro may only be used in an asynchronous function context."
41304130
[binding & body]
41314131
(if (operator/ne 2 (count binding))
41324132
(throw
@@ -4144,14 +4144,14 @@
41444144
(catch python/StopAsyncIteration _
41454145
val#))))))
41464146

4147-
(defmacro awith
4147+
(defmacro with-async
41484148
"Evaluate ``body`` within a ``try`` / ``except`` expression, binding the named
41494149
expressions as per Python's async context manager protocol spec (Python's
41504150
``async with`` blocks).
41514151

41524152
.. warning::
41534153

4154-
The ``awith`` macro may only be used in an asynchronous function context."
4154+
The ``with-async`` macro may only be used in an asynchronous function context."
41554155
[bindings & body]
41564156
(let [binding (first bindings)
41574157
expr (second bindings)]

tests/basilisp/test_core_async_macros.lpy

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@
99
(asyncio/set-event-loop loop)
1010
(.run-until-complete loop (apply f args))))
1111

12-
(deftest awith-test
12+
(deftest with-async-test
1313
(testing "base case"
1414
(let [get-val (contextlib/asynccontextmanager
1515
(fn ^:async get-val
1616
[]
1717
(yield :async-val)))
1818
val-ctxmgr (fn ^:async yield-val
1919
[]
20-
(awith [v (get-val)]
21-
v))]
20+
(with-async [v (get-val)]
21+
v))]
2222
(is (= :async-val (async-to-sync val-ctxmgr))))))
2323

24-
(deftest afor-test
24+
(deftest for-async-test
2525
(testing "base case"
2626
(let [get-vals (fn ^:async get-vals
2727
[]
@@ -30,8 +30,8 @@
3030
val-loop (fn ^:async val-loop
3131
[]
3232
(let [a (atom [])
33-
res (afor [v (get-vals)]
34-
(swap! a conj v)
35-
v)]
33+
res (for-async [v (get-vals)]
34+
(swap! a conj v)
35+
v)]
3636
[@a res]))]
3737
(is (= [[0 1 2 3 4] 4] (async-to-sync val-loop))))))

0 commit comments

Comments
 (0)