thread-utils
until-timeout
thread-loop
8.12

thread-utils🔗ℹ

Roman Klochkov <kalimehtar@mail.ru>

 (require thread-utils) package: thread-utils

This package provides some utilities to do common patterns of async programming.

procedure

(until-timeout func [timeout on-error])  any/c

  func : (-> any/c)
  timeout : (or/c #f (and/c real? (not/c negative?)) (-> any))
   = 30
  on-error : any/c = #f
Calls func and wait for answer not more then timeout. If func fails to complete until that moment and on-error is a procedure, then returns (on-error #f). If func raise an exception, applies on-error to the exception and returns it’s result. If on-error any other value, then it will be returned in case of error or timeout.

procedure

(thread-loop func [on-error])  thread?

  func : (-> any/c)
  on-error : any/c = #f
Returns thread, which runs func in infinite loop. When func raises an exception, applies on-error to the exception and run func again. If on-error is not a procedure, then errors are supressed.