concurrency.distributed-docs: update the Example article
							parent
							
								
									e82ee2d723
								
							
						
					
					
						commit
						ca08bfd4b0
					
				| 
						 | 
				
			
			@ -10,27 +10,29 @@ HELP: start-node
 | 
			
		|||
 | 
			
		||||
ARTICLE: "concurrency.distributed.example" "Distributed Concurrency Example"
 | 
			
		||||
"In this example the Factor instance associated with port 9000 will run "
 | 
			
		||||
"a thread that receives and prints messages "
 | 
			
		||||
"in the listener. The code to start the thread is:"
 | 
			
		||||
{ $examples
 | 
			
		||||
    { $unchecked-example
 | 
			
		||||
        ": log-message ( -- ) receive . flush log-message ;"
 | 
			
		||||
        "[ log-message ] \"logger\" spawn dup name>> register-remote-thread"
 | 
			
		||||
    }
 | 
			
		||||
"a thread that receives and prints messages in the listener. "
 | 
			
		||||
"The code to run the server is:"
 | 
			
		||||
{ $code
 | 
			
		||||
  "USING: io.servers ;"
 | 
			
		||||
  "9000 local-server <node-server> start-server drop"
 | 
			
		||||
}
 | 
			
		||||
"This spawns a thread waits for the messages. It registers that thread as "
 | 
			
		||||
"able to be accessed remotely using " { $link register-remote-thread } "."
 | 
			
		||||
"The code to start the thread is:"
 | 
			
		||||
{ $code
 | 
			
		||||
    "USING: concurrency.messaging threads ;"
 | 
			
		||||
    ": log-message ( -- ) receive . flush log-message ;"
 | 
			
		||||
    "[ log-message ] \"logger\" spawn dup name>> register-remote-thread"
 | 
			
		||||
}
 | 
			
		||||
"This spawns a thread that waits for the messages and prints them. It registers "
 | 
			
		||||
"the thread as remotely accessible with " { $link register-remote-thread } "."
 | 
			
		||||
$nl
 | 
			
		||||
"The second Factor instance, the one associated with port 9001, can send "
 | 
			
		||||
"messages to the 'logger' thread by name:"
 | 
			
		||||
{ $examples
 | 
			
		||||
    { $unchecked-example
 | 
			
		||||
        "USING: io.sockets concurrency.messaging concurrency.distributed ;"
 | 
			
		||||
        "\"hello\" \"127.0.0.1\" 9000 <inet4> \"logger\" <remote-thread> send"
 | 
			
		||||
    }
 | 
			
		||||
{ $code
 | 
			
		||||
    "USING: io.sockets ; FROM: concurrency.messaging => send ;"
 | 
			
		||||
    "\"hello\" \"127.0.0.1\" 9000 <inet4> \"logger\" <remote-thread> send"
 | 
			
		||||
}
 | 
			
		||||
"The " { $link send } " word is used to send messages to other threads. If an "
 | 
			
		||||
"instance of " { $link remote-thread } " is provided instead of a thread then "
 | 
			
		||||
"The " { $link send } " word is used to send messages to threads. If an "
 | 
			
		||||
"instance of " { $link remote-thread } " is provided, then "
 | 
			
		||||
"the message is marshalled to the named thread on the given machine using the "
 | 
			
		||||
{ $vocab-link "serialize" } " vocabulary."
 | 
			
		||||
$nl
 | 
			
		||||
| 
						 | 
				
			
			@ -39,9 +41,9 @@ $nl
 | 
			
		|||
$nl
 | 
			
		||||
"It is also possible to use " { $link send-synchronous } " to receive a "
 | 
			
		||||
"response to a distributed message. When an instance of " { $link thread } " "
 | 
			
		||||
"is marshalled it is converted into an instance of " { $link remote-thread }
 | 
			
		||||
"is marshalled, it is converted into an instance of " { $link remote-thread }
 | 
			
		||||
". The receiver of this can use it as the target of a " { $link send }
 | 
			
		||||
" or " { $link reply } " call." ;
 | 
			
		||||
", " { $link send-synchronous } " or " { $link reply-synchronous } " call." ;
 | 
			
		||||
 | 
			
		||||
ARTICLE: "concurrency.distributed" "Distributed message passing"
 | 
			
		||||
"The " { $vocab-link "concurrency.distributed" } " implements transparent distributed message passing, inspired by Erlang and Termite." $nl
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue