| // Copyright 2015 The Vanadium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| // WaitForNotifications waits till all notifications in 'wants' have been received, |
| // or the timeout expires. |
| func WaitForNotifications(notify <-chan interface{}, timeout time.Duration, wants ...interface{}) error { |
| timer := make(<-chan time.Time) |
| timer = time.After(timeout) |
| received := make(map[interface{}]struct{}) |
| want := make(map[interface{}]struct{}) |
| for _, w := range wants { |
| if _, exists := want[n]; !exists { |
| return fmt.Errorf("unexpected notification %v", n) |
| if reflect.DeepEqual(received, want) { |
| // No notification wanted. |
| return fmt.Errorf("timeout after receiving %v", reflect.ValueOf(received).MapKeys()) |