// Close represents mongo session closing within the context deadline
Close represents mongo session closing within the context deadline
// Close represents mongo session closing within the context deadline
func (ms *MongoConnection) Close(ctx context.Context) error {
	closedChannel := make(chan bool)
	defer close(closedChannel)
	closeTimeLeft := timeLeft
	if deadline, ok := ctx.Deadline(); ok {
		closeTimeLeft = deadline.Sub(time.Now()) + (10 * time.Millisecond)
	}
	go func() {
		start.shutdown(ctx, ms.client, closedChannel)
		return
	}()
	select {
	case <-time.After(closeTimeLeft):
		return errors.New("closing mongo timed out")
	case <-closedChannel:
		return nil
	case <-ctx.Done():
		return ctx.Err()
	}
}
func ( ms * MongoConnection ) Close ( ctx context . Context ) error { closedChannel := make ( chan bool ) defer close ( closedChannel ) closeTimeLeft := timeLeft if deadline , ok := ctx . Deadline ( ) ; ok { closeTimeLeft = deadline . Sub ( time . Now ( ) ) + ( 10 * time . Millisecond ) } go func ( ) { start . shutdown ( ctx , ms . client , closedChannel ) return } ( ) select { case <- time . After ( closeTimeLeft ) : return errors . New ( " " ) case <- closedChannel : return nil case <- ctx . Done ( ) : return ctx . Err ( ) } }
Close represents mongo session closing within the context deadline
Close represents mongo session closing within the context deadline
// Make a copy of timeLeft so that we don't modify the global var // Add some time to timeLeft so case where ctx.Done in select // statement below gets called before time.After(timeLeft) gets called. // This is so the context error is returned over hardcoded error.