Commits

Limburgse Natuurgidsen committed 3bfe4c6

Small thread update - still just mental...

Comments (0)

Files changed (1)

json-rpc-client.scm

 	((not (output-port? output)) (server-setup-arguments-error "output port" "ouput-port" (get-type output)))
 	((not (is-valid-version? version)) (server-setup-arguments-error "version" "2.0" version))
 	(else
-	 (thread-start! (thread-listener input))
-	 ;(thread-start! thread-public)
+	 (thread-start! (listener-thread input (current-thread))) ;Start the looping listener thread
 	 (lambda (method . params)
 	   (cond ((not (is-valid-method? method)) (server-setup-data-error "method" "can only be a string or a symbol."))
 		 ((not (are-valid-params? params)) (server-setup-data-error "params" "can only be a vector or an alist."))
   (write-json request output))
 
 ; Create the looping listener thread which will dispatch messages to various thread-mailboxes
-;; Keep reading the JSON sent back from the server, if the ID is equal to the sender, dispatch a message
-;; to the current threads mailbox. Otherwise send the message to the public threads mailbox. 
-(define (thread-listener input) 
-  (make-thread (lambda () (loop
-			   (let ((data (read-json input #f)))
-			     (cond ((alist-ref 'id data) (thread-send (current-thread) "There is a response"))
-				   (thread-send (current-thread) "This is a service announcment")))))
+;; Keep reading the JSON sent back from the server, if the reponse contains an  ID and this ID is 
+;; equal to the sender, dispatch a message to the current threads mailbox. 
+;; Otherwise send the message to the public threads mailbox. 
+(define (listener-thread input current-thread) 
+  (make-thread (lambda () 
+		 (loop
+		  (if 
+		   (alist-ref 'id (read-json input #f))
+		   (thread-send current-thread "There is a response"))))
 	       'listener))
 
-; Create the "public" thread which mailbox is used for server messages intended for all clients.
-;(define thread-public
-;  (make-thread (lambda () (pp (thread-receive 999))) 'public))
- 
 )