guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[shepherd] 01/03: service: Rewrite 'launch-service' in functional style.


From: Ludovic Courtès
Subject: [shepherd] 01/03: service: Rewrite 'launch-service' in functional style.
Date: Wed, 13 Jan 2016 22:49:05 +0000

civodul pushed a commit to branch master
in repository shepherd.

commit e3183039ec327d803f7b25504dcb05c77a880b2b
Author: Ludovic Courtès <address@hidden>
Date:   Wed Jan 13 22:04:58 2016 +0100

    service: Rewrite 'launch-service' in functional style.
    
    * modules/shepherd/service.scm (launch-service): Rewrite in a functional
    style.
---
 modules/shepherd/service.scm |   33 +++++++++++++++++----------------
 1 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index 849f1fe..f50e328 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -434,22 +434,23 @@ clients."
 ;; Try to start (with PROC) a service providing NAME.  Used by `start'
 ;; and `enforce'.
 (define (launch-service name proc args)
-  (let* ((possibilities (lookup-services name))
-        (which (first-running possibilities)))
-    (if (null? possibilities)
-       (local-output "No service provides ~a." name)
-        (or which
-            ;; None running yet, start one.
-            (set! which (find (lambda (service)
-                                (apply proc service args))
-                              possibilities))))
-    (or which
-       (let ((unknown (lookup-running 'unknown)))
-         (if (and unknown
-                  (defines-action? unknown 'start))
-             (apply action unknown 'start name args)
-           (local-output "Providing ~a impossible." name))))
-    (and which #t)))
+  (match (lookup-services name)
+    (()
+     (local-output "No service provides ~a." name))
+    ((possibilities ...)
+     (or (first-running possibilities)
+
+         ;; None running yet, start one.
+         (find (lambda (service)
+                 (apply proc service args))
+               possibilities)
+
+         ;; Failed to start something, try the 'unknown' service.
+         (let ((unknown (lookup-running 'unknown)))
+           (if (and unknown
+                    (defines-action? unknown 'start))
+               (apply action unknown 'start name args)
+               (local-output "Providing ~a impossible." name)))))))
 
 ;; Starting by name.
 (define-method (start (obj <symbol>) . args)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]