Skip to content

Commit

Permalink
Fix deref timeout interface
Browse files Browse the repository at this point in the history
Signed-off-by: James Hamlin <[email protected]>
  • Loading branch information
jfhamlin committed Aug 16, 2023
1 parent 857dc92 commit b816f5b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
10 changes: 5 additions & 5 deletions pkg/lang/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ func (f *future) Deref() interface{} {
return f.res
}

func (f *future) DerefWithTimeout(ms int64, timeoutValue interface{}) interface{} {
func (f *future) DerefWithTimeout(timeout int64, timeUnit time.Duration) interface{} {
select {
case <-f.done:
return f.res
case <-time.After(time.Duration(ms) * time.Millisecond):
return timeoutValue
case <-time.After(time.Duration(timeout) * timeUnit):
return nil
}
}

func (f *future) Get() interface{} {
return f.Deref()
}

func (f *future) GetWithTimeout(ms int64, timeoutValue interface{}) interface{} {
return f.DerefWithTimeout(ms, timeoutValue)
func (f *future) GetWithTimeout(timeout int64, timeUnit time.Duration) interface{} {
return f.DerefWithTimeout(timeout, timeUnit)
}

func (f *future) IsRealized() bool {
Expand Down
5 changes: 3 additions & 2 deletions pkg/lang/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package lang
import (
"fmt"
"reflect"
"time"
)

type (
Expand Down Expand Up @@ -255,7 +256,7 @@ type (
}

IBlockingDeref interface {
DerefWithTimeout(ms int64, timeoutValue interface{}) interface{}
DerefWithTimeout(timeout int64, timeUnit time.Duration) interface{}
}

IRef interface {
Expand Down Expand Up @@ -287,7 +288,7 @@ type (
// Java Future interface
Future interface {
Get() interface{}
GetWithTimeout(timeout int64, timeoutValue interface{}) interface{}
GetWithTimeout(timeout int64, timeUnit time.Duration) interface{}
// Cancel(mayInterruptIfRunning bool) bool
// IsCancelled() bool
// IsDone() bool
Expand Down

0 comments on commit b816f5b

Please sign in to comment.