Commits

Limburgse Natuurgidsen  committed 21331ef

Broken thread experiment - saving for mental reference...

  • Participants
  • Parent commits 8fa75b8

Comments (0)

Files changed (7)

File .hgtags

File contents unchanged.

File README.md

File contents unchanged.

File json-rpc-client.scm

   (json-rpc-server)
 
 (import chicken scheme)
-(use medea extras srfi-1 data-structures)
+(use medea extras srfi-1 data-structures mailbox-threads loop)
 
 ; Setup the custom error handlers
 (define (server-setup-arguments-error type expected given)
 	((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)
 	 (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."))
 (define (send-request request output)
   (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")))))
+	       '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))
+ 
 )

File json-rpc.meta

File contents unchanged.

File json-rpc.setup

File contents unchanged.

File release-info

File contents unchanged.

File tests/run.scm

File contents unchanged.