We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b082405 commit 6871577Copy full SHA for 6871577
aio-test.el
@@ -113,3 +113,25 @@ aio-timeout to cause the test to fail."
113
(nth 1 (aio-chain (cdr filter)))))
114
(should (equal "1 2 3\n"
115
(nth 1 (aio-chain (cdr filter))))))))
116
+
117
+(ert-deftest sem ()
118
+ (aio-with-test 5
119
+ (let ((n 64)
120
+ (sem (aio-sem 0))
121
+ (promises ())
122
+ (output ()))
123
+ (dotimes (i n)
124
+ ;; Queue up threads on the semaphore
125
+ (push
126
+ (aio-with-async
127
+ (aio-await (aio-sem-wait sem))
128
+ (push i output))
129
+ promises))
130
+ ;; Allow threads to run
131
+ (dotimes (_ n)
132
+ (aio-sem-post sem))
133
+ ;; Wait for all threads to complete (join)
134
+ (aio-await (aio-all promises))
135
+ ;; Check that the threads ran in correct order
136
+ (should (equal (number-sequence 0 63)
137
+ (nreverse output))))))
0 commit comments