Skip to content

Commit

Permalink
Rename variable fea to fut
Browse files Browse the repository at this point in the history
  • Loading branch information
timandy committed Jul 20, 2022
1 parent 4a6d21e commit 6c6f27b
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 90 deletions.
8 changes: 4 additions & 4 deletions api_future_test.go
Expand Up @@ -7,10 +7,10 @@ import (
)

func TestNewFuture(t *testing.T) {
fea := NewFuture()
assert.NotNil(t, fea)
fut := NewFuture()
assert.NotNil(t, fut)
//
p, ok := fea.(*future)
assert.Same(t, p, fea)
p, ok := fut.(*future)
assert.Same(t, p, fut)
assert.True(t, ok)
}
20 changes: 10 additions & 10 deletions api_routine.go
Expand Up @@ -49,14 +49,14 @@ func Go(fun Runnable) {
// This function return a Future pointer, so we can wait by Future.Get method.
// If panic occur in goroutine, The panic will be trigger again when calling Future.Get method.
func GoWait(fun Runnable) Future {
fea := NewFuture()
fut := NewFuture()
// backup
copied := createInheritedMap()
go func() {
// catch
defer func() {
if cause := recover(); cause != nil {
fea.CompleteError(NewRuntimeError(cause))
fut.CompleteError(NewRuntimeError(cause))
}
}()
// restore
Expand All @@ -71,7 +71,7 @@ func GoWait(fun Runnable) Future {
}
}()
fun()
fea.Complete(nil)
fut.Complete(nil)
} else {
backup := t.inheritableThreadLocals
defer func() {
Expand All @@ -81,24 +81,24 @@ func GoWait(fun Runnable) Future {
t.threadLocals = nil
t.inheritableThreadLocals = copied
fun()
fea.Complete(nil)
fut.Complete(nil)
}
}()
return fea
return fut
}

// GoWaitResult starts a new goroutine, and copy inheritableThreadLocals from current goroutine.
// This function return a Future pointer, so we can wait and get result by Future.Get method.
// If panic occur in goroutine, The panic will be trigger again when calling Future.Get method.
func GoWaitResult(fun Callable) Future {
fea := NewFuture()
fut := NewFuture()
// backup
copied := createInheritedMap()
go func() {
// catch
defer func() {
if cause := recover(); cause != nil {
fea.CompleteError(NewRuntimeError(cause))
fut.CompleteError(NewRuntimeError(cause))
}
}()
// restore
Expand All @@ -112,7 +112,7 @@ func GoWaitResult(fun Callable) Future {
t.inheritableThreadLocals = nil
}
}()
fea.Complete(fun())
fut.Complete(fun())
} else {
backup := t.inheritableThreadLocals
defer func() {
Expand All @@ -121,8 +121,8 @@ func GoWaitResult(fun Callable) Future {
}()
t.threadLocals = nil
t.inheritableThreadLocals = copied
fea.Complete(fun())
fut.Complete(fun())
}
}()
return fea
return fut
}
24 changes: 12 additions & 12 deletions api_routine_test.go
Expand Up @@ -117,11 +117,11 @@ func TestGo_Cross(t *testing.T) {
func TestGoWait_Error(t *testing.T) {
run := false
assert.Panics(t, func() {
fea := GoWait(func() {
fut := GoWait(func() {
run = true
panic("error")
})
fea.Get()
fut.Get()
})
assert.True(t, run)
}
Expand All @@ -130,11 +130,11 @@ func TestGoWait_Nil(t *testing.T) {
assert.Nil(t, createInheritedMap())
//
run := false
fea := GoWait(func() {
fut := GoWait(func() {
assert.Nil(t, createInheritedMap())
run = true
})
assert.Nil(t, fea.Get())
assert.Nil(t, fut.Get())
assert.True(t, run)
}

Expand All @@ -150,7 +150,7 @@ func TestGoWait_Value(t *testing.T) {
assert.NotNil(t, createInheritedMap())
//
run := false
fea := GoWait(func() {
fut := GoWait(func() {
assert.NotNil(t, createInheritedMap())
//
assert.Nil(t, tls.Get())
Expand All @@ -164,7 +164,7 @@ func TestGoWait_Value(t *testing.T) {
//
run = true
})
assert.Nil(t, fea.Get())
assert.Nil(t, fut.Get())
assert.True(t, run)
//
assert.Equal(t, "Hello", tls.Get())
Expand All @@ -184,14 +184,14 @@ func TestGoWait_Cross(t *testing.T) {
func TestGoWaitResult_Error(t *testing.T) {
run := false
assert.Panics(t, func() {
fea := GoWaitResult(func() Any {
fut := GoWaitResult(func() Any {
run = true
if run {
panic("error")
}
return 1
})
fea.Get()
fut.Get()
})
assert.True(t, run)
}
Expand All @@ -200,12 +200,12 @@ func TestGoWaitResult_Nil(t *testing.T) {
assert.Nil(t, createInheritedMap())
//
run := false
fea := GoWaitResult(func() Any {
fut := GoWaitResult(func() Any {
assert.Nil(t, createInheritedMap())
run = true
return true
})
assert.True(t, fea.Get().(bool))
assert.True(t, fut.Get().(bool))
assert.True(t, run)
}

Expand All @@ -221,7 +221,7 @@ func TestGoWaitResult_Value(t *testing.T) {
assert.NotNil(t, createInheritedMap())
//
run := false
fea := GoWaitResult(func() Any {
fut := GoWaitResult(func() Any {
assert.NotNil(t, createInheritedMap())
//
assert.Nil(t, tls.Get())
Expand All @@ -236,7 +236,7 @@ func TestGoWaitResult_Value(t *testing.T) {
run = true
return true
})
assert.True(t, fea.Get().(bool))
assert.True(t, fut.Get().(bool))
assert.True(t, run)
//
assert.Equal(t, "Hello", tls.Get())
Expand Down
48 changes: 24 additions & 24 deletions api_thread_local_test.go
Expand Up @@ -40,11 +40,11 @@ func TestNewThreadLocal_Single(t *testing.T) {
tls2.Set(33)
assert.Equal(t, 33, tls2.Get())
//
fea := GoWait(func() {
fut := GoWait(func() {
assert.Nil(t, tls.Get())
assert.Nil(t, tls2.Get())
})
fea.Get()
fut.Get()
}

func TestNewThreadLocal_Multi(t *testing.T) {
Expand All @@ -58,11 +58,11 @@ func TestNewThreadLocal_Multi(t *testing.T) {
tls2.Set(33)
assert.Equal(t, 33, tls2.Get())
//
fea := GoWait(func() {
fut := GoWait(func() {
assert.Nil(t, tls.Get())
assert.Nil(t, tls2.Get())
})
fea.Get()
fut.Get()
}

func TestNewThreadLocal_Concurrency(t *testing.T) {
Expand Down Expand Up @@ -96,11 +96,11 @@ func TestNewThreadLocal_Concurrency(t *testing.T) {
}
wg.Wait()
//
fea := GoWait(func() {
fut := GoWait(func() {
assert.Nil(t, tls.Get())
assert.Nil(t, tls2.Get())
})
fea.Get()
fut.Get()
}

//===
Expand All @@ -120,11 +120,11 @@ func TestNewThreadLocalWithInitial_Single(t *testing.T) {
tls2.Set(33)
assert.Equal(t, 33, tls2.Get())
//
fea := GoWait(func() {
fut := GoWait(func() {
assert.Equal(t, "Hello", tls.Get())
assert.Equal(t, 22, tls2.Get())
})
fea.Get()
fut.Get()
}

func TestNewThreadLocalWithInitial_Multi(t *testing.T) {
Expand All @@ -142,11 +142,11 @@ func TestNewThreadLocalWithInitial_Multi(t *testing.T) {
tls2.Set(33)
assert.Equal(t, 33, tls2.Get())
//
fea := GoWait(func() {
fut := GoWait(func() {
assert.Equal(t, "Hello", tls.Get())
assert.Equal(t, 22, tls2.Get())
})
fea.Get()
fut.Get()
}

func TestNewThreadLocalWithInitial_Concurrency(t *testing.T) {
Expand Down Expand Up @@ -184,11 +184,11 @@ func TestNewThreadLocalWithInitial_Concurrency(t *testing.T) {
}
wg.Wait()
//
fea := GoWait(func() {
fut := GoWait(func() {
assert.Equal(t, "Hello", tls.Get())
assert.Equal(t, 22, tls2.Get())
})
fea.Get()
fut.Get()
}

//===
Expand All @@ -206,11 +206,11 @@ func TestNewInheritableThreadLocal_Single(t *testing.T) {
tls2.Set(33)
assert.Equal(t, 33, tls2.Get())
//
fea := GoWait(func() {
fut := GoWait(func() {
assert.Equal(t, "Hello", tls.Get())
assert.Equal(t, 33, tls2.Get())
})
fea.Get()
fut.Get()
}

func TestNewInheritableThreadLocal_Multi(t *testing.T) {
Expand All @@ -224,11 +224,11 @@ func TestNewInheritableThreadLocal_Multi(t *testing.T) {
tls2.Set(33)
assert.Equal(t, 33, tls2.Get())
//
fea := GoWait(func() {
fut := GoWait(func() {
assert.Equal(t, "Hello", tls.Get())
assert.Equal(t, 33, tls2.Get())
})
fea.Get()
fut.Get()
}

func TestNewInheritableThreadLocal_Concurrency(t *testing.T) {
Expand Down Expand Up @@ -262,11 +262,11 @@ func TestNewInheritableThreadLocal_Concurrency(t *testing.T) {
}
wg.Wait()
//
fea := GoWait(func() {
fut := GoWait(func() {
assert.Nil(t, tls.Get())
assert.Equal(t, 33, tls2.Get())
})
fea.Get()
fut.Get()
}

//===
Expand All @@ -286,11 +286,11 @@ func TestNewInheritableThreadLocalWithInitial_Single(t *testing.T) {
tls2.Set(33)
assert.Equal(t, 33, tls2.Get())
//
fea := GoWait(func() {
fut := GoWait(func() {
assert.Equal(t, "Hello", tls.Get())
assert.Equal(t, 33, tls2.Get())
})
fea.Get()
fut.Get()
}

func TestNewInheritableThreadLocalWithInitial_Multi(t *testing.T) {
Expand All @@ -308,11 +308,11 @@ func TestNewInheritableThreadLocalWithInitial_Multi(t *testing.T) {
tls2.Set(33)
assert.Equal(t, 33, tls2.Get())
//
fea := GoWait(func() {
fut := GoWait(func() {
assert.Equal(t, "Hello", tls.Get())
assert.Equal(t, 33, tls2.Get())
})
fea.Get()
fut.Get()
}

func TestNewInheritableThreadLocalWithInitial_Concurrency(t *testing.T) {
Expand Down Expand Up @@ -350,11 +350,11 @@ func TestNewInheritableThreadLocalWithInitial_Concurrency(t *testing.T) {
}
wg.Wait()
//
fea := GoWait(func() {
fut := GoWait(func() {
assert.Equal(t, "Hello", tls.Get())
assert.Equal(t, 33, tls2.Get())
})
fea.Get()
fut.Get()
}

//===
Expand Down

0 comments on commit 6c6f27b

Please sign in to comment.