This project implements a "Quartz Clock" similar to a real digital watch / clock.
A high frequency (a power of 2) input source signal is used to generate a 1 second output signal - serving as the "ticking" input for the clock.
Frequency dividers (also called flip-flops) are implemented as goroutine and share an input and output channel with the previous and next flip-flop (or are used as the source signal / output signal).
go run main.go -durationSeconds 3
Starting
=> 2022-02-13 23:37:30.488941189 +0100 CET m=+1.001053330
=> 2022-02-13 23:37:31.488604518 +0100 CET m=+2.000716655
=> 2022-02-13 23:37:32.488471204 +0100 CET m=+3.000583350
Exiting
Obviously, this project has no use beside explanation / training.
An equivalent, more performant and accurate implementation is simply :
time.Ticker(1 * time.Second)