Sobes.tech
Junior — Senior

Parallel query to multiple database replicas

livecode

Task condition

There are three database replica addresses. It is necessary to write a function that simultaneously (in parallel goroutines) requests the value for a given key from each replica. As soon as one replica returns a correct result (a value different from ErrNotFound and without errors), the function should immediately return the obtained value and cancel the waiting for the other requests.

127.0.0.1  
127.0.0.2  
127.0.0.3

The following method is provided for operation (its implementation already exists):

var ErrNotFound = errors.New("not found")

func Get(ctx context.Context, address, key string) (string, error) {
    return "", nil // already implemented
}