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

timeout usage is cumbersome #54

Closed
leonoel opened this issue Dec 17, 2021 · 1 comment
Closed

timeout usage is cumbersome #54

leonoel opened this issue Dec 17, 2021 · 1 comment
Labels
breaking change A bad design decision was made

Comments

@leonoel
Copy link
Owner

leonoel commented Dec 17, 2021

When the target task fails to complete within given delay, the task fails and the error is not easy to check for recovery (in addition of not being documented). The timeout case could result in a success with a user-provided value, akin to the timed out version of deref. The timeout value could be optional and default to nil, like sleep.

(defn timeout
  ([task delay] (timeout task delay nil))
  ([task delay value]
   (-> task
     (attempt)
     (race (sleep delay #(-> value)))
     (absolve))))
(m/? (timeout (m/sleep 20 :a) 25 :b)) ;; :a after 20ms
(m/? (timeout (m/sleep 20 :a) 15 :b)) ;; :b after 15ms
(m/? (timeout (m/sleep 20 :a) 15))    ;; nil after 15ms
@leonoel leonoel added the breaking change A bad design decision was made label Dec 17, 2021
@leonoel
Copy link
Owner Author

leonoel commented Dec 24, 2021

Fixed in b.25

@leonoel leonoel closed this as completed Dec 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change A bad design decision was made
Projects
None yet
Development

No branches or pull requests

1 participant