Example #1
0
func callService(cid uint, t0 time.Time) future.Future {

	// create the Future object
	fobj := future.NewUntypedFuture()

	// create an asyncRequest
	// server will use future object to post its response
	request := &asyncRequest{cid, time.Now(), fobj}

	// queue the request
	server <- request

	// Return the FutureResult of the Future object to the caller
	return fobj
}
func startClients() {
	for i := 0; i < _NUM_CLIENTS; i++ {
		go func(cid int) {
			var n = 0
			var tocnt = 0
			var t0 time.Time = time.Now()
			var delta time.Duration
			var timeout bool

			for true {
				future := future.NewUntypedFuture()
				request := &request{cid, time.Now(), future}
				server <- request

				// note: typically get would occur elsewhere and not immediately after request
				_, timeout = future.Result().TryGet(time.Duration(_WAIT))
				if timeout {
					future.Result().Get()
				}

				// client 0 will dump its results as a sample
				if cid == 0 {
					if timeout {
						tocnt++
					}

					n++
					if n >= _REPORT_LIM {
						delta = time.Now().Sub(t0)
						log.Printf("(sample of %d) : %04d requests in %d nsec with %d timeouts (recovered)\n", _NUM_CLIENTS, n, delta, tocnt)
						n = 0
						tocnt = 0
					}
					if n == 0 {
						t0 = time.Now()
					}
				}
			}
		}(i)
	}
}