2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -0,0 +1,37 @@
(ns async-example.core
(:require [clojure.core.async :refer [>! <! >!! <!! go chan]])
(:require [clj-time.core :as time])
(:require [clj-time.format :as time-format])
(:gen-class))
;; Helper functions (logging & time stamp)
; Time stamp format
(def custom-formatter (time-format/formatter "yyyy:MM:dd:ss.SS"))
(defn safe-println [& more]
" This function avoids interleaving of text output when using println due to race condition for multi-processes printing
as discussed http://yellerapp.com/posts/2014-12-11-14-race-condition-in-clojure-println.html "
(.write *out* (str (clojure.string/join " " more) "\n")))
(defn log [s]
" Outputs mesage with time stamp "
(safe-println (time-format/unparse custom-formatter (time/now)) ":" s))
;; Main code
(defn -main [& args]
(let [c (chan)]
(log "Program start")
(go
(log "Task start")
(log (str "Event received by task: "(<! c))))
(<!!
(go
(log "program sleeping")
(Thread/sleep 1000) ; Wait 1 second
(log "Program signaling event")
(>! c "reset") ; Send message to task
))))
; Invoke -main function
(-main)

View file

@ -1,16 +1,18 @@
/*REXX program shows a method of handling events (this is time-driven). */
signal on halt /*allow the user to HALT the pgm.*/
parse arg timeEvent /*allow "event" to be specified. */
if timeEvent='' then timeEvent=5 /*if not specified, use default. */
/*REXX program demonstrates a method of handling events (this is a time─driven pgm).*/
signal on halt /*allow the user to HALT the program.*/
parse arg timeEvent /*allow the "event" to be specified. */
if timeEvent='' then timeEvent=5 /*Not specified? Then use the default.*/
event?: do forever /*determine if an event occurred.*/
theEvent=right(time(),1) /*maybe it's an event, maybe not.*/
event?: do forever /*determine if an event has occurred. */
theEvent=right(time(),1) /*maybe it's an event, ─or─ maybe not.*/
if pos(theEvent,timeEvent)\==0 then signal happening
end /*forever*/
say 'Control should never get here!' /*This is a logic no-no occurance*/
halt: say 'program halted.'; exit /*stick a fork in it, we're done.*/
/*───────────────────────────────────HAPPENING processing───────────────*/
happening: say 'an event occurred at' time()", the event is:" theEvent
do while theEvent==right(time(),1); /*process the event here.*/ nop;end
signal event? /*see if another event happened. */
say 'Control should never get here!' /*This is a logic can─never─happen ! */
halt: say ' program halted.'; exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
happening: say 'an event occurred at' time()", the event is:" theEvent
do while theEvent==right(time(),1)
nop /*replace NOP with the "process" code.*/
end /*while*/ /*NOP is a special REXX statement. */
signal event? /*see if another event has happened. */