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

how to set timeouts with aio #28

Open
mooseyboots opened this issue Jun 14, 2022 · 2 comments
Open

how to set timeouts with aio #28

mooseyboots opened this issue Jun 14, 2022 · 2 comments

Comments

@mooseyboots
Copy link

i just gave this a library a go for a simple url-retrieve functionality.

i'm wondering how to set a timeout for it?

so far i just used code as in your example:

((let ((response (aio-await (aio-url-retrieve url))))
  do stuff w/ (cdr response)

i see there's aio-timeout and aio-idle but it's unclear to me how to use these to give up on such a request, if that's even what they can be used for? (since using aio in my code, sometimes a response comes in about 10 minutes late, longer after i have given up and re-run the command to fetch the url.

@alphapapa
Copy link

Take a look at

(defmacro aio-with-test (timeout &rest body)

@mooseyboots
Copy link
Author

mooseyboots commented Jul 24, 2023

thanks for the pointer, i think i have something working with it.

(defmacro aio-with-timeout (timeout &rest body)
  "Run body asynchronously.

If TIMEOUT seconds passes without completion, signal an
aio-timeout error."
  (declare (indent 1))
  `(let* ((promises (list (aio-with-async ,@body)
                          (aio-timeout ,timeout)))
          (select (aio-make-select promises)))
     (aio-with-async
       (aio-await (aio-await (aio-select select))))))

it would be nice gracefully handle a timeout rather than just have the aio-timeout error , which to me appears as Error running timer ‘funcall’: (aio-timeout . 0). but thats for another day for me.

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