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

Understanding aio-defun #25

Open
Silex opened this issue Feb 8, 2022 · 1 comment
Open

Understanding aio-defun #25

Silex opened this issue Feb 8, 2022 · 1 comment

Comments

@Silex
Copy link

Silex commented Feb 8, 2022

Hello,

The following code works:

(defun aio-call-process (program &rest args)
  (let* ((process (apply #'start-file-process program "*aio-call-process*" program args))
         (promise (aio-promise)))
    (prog1
        promise
      (setf (process-sentinel process) (-partial #'aio-process-sentinel promise)))))

(defun aio-process-sentinel (promise proc status)
  "Sentinel that resolves the PROMISE using PROC and STATUS."
  (aio-resolve
   promise
   (lambda ()
     (with-current-buffer (process-buffer proc)
       (prog1
           (buffer-substring-no-properties (point-min) (point-max))
         (kill-buffer))))))

(aio-defun aio-run (command &rest args)
  (interactive)
  (message "Start")
  (message (aio-await (apply #'aio-call-process command args)))
  (message "Stop"))

(aio-run "echo" "123")

But if I just change (defun aio-call-process (program &rest args) to (aio-defun aio-call-process (program &rest args) then nothing works anymore. I'm confused, can you clarify why?

I thought aio-defun was to enable aio-await but that it was still somewhat of a normal function.

Also, apparently I'm supposed to use aio-make-callback to simplify the code above but honestly I have no clue how 😅

@justinbarclay
Copy link

I am definitely running into the last line here - I'm curious how aio-make-callback simplifies working with start-process or make-process

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

No branches or pull requests

2 participants