From 7abb751eb3d9213ba690ed4ae6b0dbbc099d8e46 Mon Sep 17 00:00:00 2001 From: LLLL Colonq Date: Tue, 22 Sep 2026 00:06:29 -0400 Subject: Update --- src/wasp-utils.el | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/wasp-utils.el') diff --git a/src/wasp-utils.el b/src/wasp-utils.el index 9f29f6dc..f588d5f4 100644 --- a/src/wasp-utils.el +++ b/src/wasp-utils.el @@ -393,5 +393,37 @@ Otherwise make it invisible." "Generate a UUID." (s-trim (shell-command-to-string "uuidgen"))) +(defun w/async-all-helper (hs cb) + "Take N functions HS and a single callback with N arguments CB. +Run all N functions and when they all finish pass all results to the callback. +The callback is the last element of HANDLERS." + (let* + ( (len (length hs)) + (finished 0) + (results (make-vector len nil))) + (--each-indexed hs + (funcall it + (lambda (res) + (setf (aref results it-index) res) + (incf finished) + (cond + ((> finished len) (error "Received more responses than expected in w/async-all!")) + ((= finished len) + (apply cb (seq-into results 'list))))))))) + +(defmacro w/async-all (&rest forms) + "Run the first FORMS in parallel and pass the results to the last form." + (let* + ( (cb (-last-item forms)) + (len (- (length forms) 1)) + (hs (-take len forms))) + `(w/async-all-helper + (list + ,@(--map + (let ((arg (gensym "w/async-all-arg"))) + `(lambda (,arg) ,(-concat it (list arg)))) + hs)) + ,cb))) + (provide 'wasp-utils) ;;; wasp-utils.el ends here -- cgit v1.3.1