-
Notifications
You must be signed in to change notification settings - Fork 60
api: replaced Future.done with a sync.Cond #508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
This commit reduces allocations. Future.done allocation replaced with - Future.cond (*sync.Cond) - Future.finished (atomic.Bool) Other code use Future.isDone() instead (Future.done == nil) check. Added Future.finish() marks Future as done. Future.WaitChan() now creates channel on demand. Closes #496
dd9e78b to
f5ce75f
Compare
oleg-jukovec
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the patch. Overall, everything's fine.
I've added some implementation notes, but you need to do a proper rebase first.
| Future.pushes[], Future.ready (#480, #497). | ||
| * `LogAppendPushFailed` replaced with `LogBoxSessionPushUnsupported` (#480) | ||
| * `LogAppendPushFailed` replaced with `LogBoxSessionPushUnsupported` (#480). | ||
| * Removed deprecated `Connection` methods, related interfaces and tests are updated (#479). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like rebase artifacts.
| *NOTE*: due to Future.GetTyped() doesn't decode SelectRequest into structure, substitute Connection.GetTyped() following the example: | ||
| ```Go | ||
| var singleTpl = Tuple{} | ||
| err = conn.GetTyped(space, index, key, &singleTpl) | ||
| ``` | ||
| At now became: | ||
| ```Go | ||
| var tpl []Tuple | ||
| err = conn.Do(NewSelectRequest(space). | ||
| Index(index). | ||
| Limit(1). | ||
| Key(key) | ||
| ).GetTyped(&tpl) | ||
| singleTpl := tpl[0] | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
etc
| if fut.done == nil { | ||
| fut.done = make(chan struct{}) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a code-style issue.
| if fut.done == nil { | |
| fut.done = make(chan struct{}) | |
| } | |
| if fut.done == nil { | |
| fut.done = make(chan struct{}) | |
| } | |
| close(fut.done) | ||
| } | ||
|
|
||
| fut.cond.Broadcast() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| fut.cond.Broadcast() | |
| fut.cond.Broadcast() | |
| case conn.rlimit <- struct{}{}: | ||
| case <-fut.done: | ||
| default: | ||
| <-fut.WaitChan() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should look like this:
| <-fut.WaitChan() | |
| default: | |
| select{ | |
| case conn.rlimit <- struct{}{}: | |
| case <-fut.WaitChan(): | |
| if fut.err == nil { | |
| panic("fut.done is closed, but err is nil") | |
| } | |
| } |
| mutex sync.Mutex | ||
| resp Response | ||
| err error | ||
| cond *sync.Cond |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| cond *sync.Cond | |
| cond sync.Cond |
This commit reduces allocations.
Future.done allocation replaced with
Other code use
Future.isDone()insteadFuture.done == nilcheck.Added Future.finish() marks Future as done.
Future.WaitChan() now creates channel on demand.
Closes #496