@cryptotaxi247 / kubo / commits / 390f4d741

readability(util) Do -> ContextDo

@jbenet

Brian Tiger Chow committed Nov 5, 2014 at 10:07 UTC 390f4d7419efa694e41d9779d01aeab3f1188672
3 files changed +6 -6
net/net.go
+1 -1
@@ -60,7 +60,7 @@ func NewIpfsNetwork(ctx context.Context, listen []ma.Multiaddr, local peer.Peer,
60 // DialPeer attempts to establish a connection to a given peer.
61 // Respects the context.
62 func (n *IpfsNetwork) DialPeer(ctx context.Context, p peer.Peer) error {
63 - err := util.Do(ctx, func() error {
63 + err := util.ContextDo(ctx, func() error {
64 _, err := n.swarm.Dial(p)
65 return err
66 })
util/do.go
+1 -1
@@ -2,7 +2,7 @@ package util
2
3 import "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
4
5 -func Do(ctx context.Context, f func() error) error {
5 +func ContextDo(ctx context.Context, f func() error) error {
6
7 ch := make(chan error)
8
util/do_test.go
+4 -4
@@ -10,7 +10,7 @@ import (
10 func TestDoReturnsContextErr(t *testing.T) {
11 ctx, cancel := context.WithCancel(context.Background())
12 ch := make(chan struct{})
13 - err := Do(ctx, func() error {
13 + err := ContextDo(ctx, func() error {
14 cancel()
15 ch <- struct{}{} // won't return
16 return nil
@@ -22,8 +22,8 @@ func TestDoReturnsContextErr(t *testing.T) {
22
23 func TestDoReturnsFuncError(t *testing.T) {
24 ctx := context.Background()
25 - expected := errors.New("expected to be returned by Do")
26 - err := Do(ctx, func() error {
25 + expected := errors.New("expected to be returned by ContextDo")
26 + err := ContextDo(ctx, func() error {
27 return expected
28 })
29 if err != expected {
@@ -33,7 +33,7 @@ func TestDoReturnsFuncError(t *testing.T) {
33
34 func TestDoReturnsNil(t *testing.T) {
35 ctx := context.Background()
36 - err := Do(ctx, func() error {
36 + err := ContextDo(ctx, func() error {
37 return nil
38 })
39 if err != nil {