Example #1
0
func Run(ctx context.Context, fc fnet.FrameConn) error {
	bs := make([]byte, fc.FrameSize())
	for {
		select {
		case <-ctx.Done():
			return ctx.Err()
		default:
		}
		if err := fc.RecvFrame(bs); err != nil {
			return err
		}
		fmt.Printf("%d %d\n", int64(binary.LittleEndian.Uint64(bs[:8])), time.Now().UnixNano())
	}
}
Example #2
0
// Start starts a new clock station. The connection argument is wrapped.
// PRE: fc :-> fnet.FrameConn
// POST: ret = error OR nil
// EFF: sends each value from ticker over fc (nanoseconds in little-endian 64-bit signed unix epoch format) until stop is called
func Run(ctx context.Context, fc fnet.FrameConn, tick <-chan time.Time) error {
	var b = make([]byte, fc.FrameSize())
	for {
		select {
		case t := <-tick:
			ns := t.UnixNano()
			binary.LittleEndian.PutUint64(b[:8], uint64(ns))
			if err := fc.SendFrame(b[:]); err != nil {
				return err
			}
			fmt.Printf("%d\n", uint64(ns))
			//		fmt.Printf("Sent frame %v", ns) yo
		case <-ctx.Done():
			return nil
		}
	}
}