Skip to content

Latest commit

 

History

History
54 lines (46 loc) · 1.44 KB

0160-moira.org

File metadata and controls

54 lines (46 loc) · 1.44 KB

moira

This small library, made by @ruricolist, implements an abstraction over bordeaux-threads. It is able to restart threads in case of errors. Moira monitors all started threads.

In the next example, I’m creating a thread which runs 5 iterations and fails. When the same thread restarted, it ends without an error:

POFTHEDAY> (moira:start-monitor)

POFTHEDAY> (let ((num-attempts 1))
             (moira:spawn "Counter"
                (format t "Starting the thread~%")
                (loop for i from 0 upto 5
                      do (format t "Iteration ~A~%" i)
                         (sleep 1)
                      finally (when (> num-attempts 0)
                                (decf num-attempts)
                                (format t "Exiting with error~%")
                                (error "Some shit happened!")))))
Starting the thread
Iteration 0
#<SB-THREAD:THREAD "Counter" RUNNING {10028CBD93}>
#<MOIRA::MONITORED-THREAD Counter>
Iteration 1
Iteration 2
Iteration 3
Iteration 4
Iteration 5
Exiting with error

Starting the thread
Iteration 0
Iteration 1
Iteration 2
Iteration 3
Iteration 4
Iteration 5

Without num-attempts trick, a thread will be restarted eternally. This is useful for long-running threads which should be kept alive.