-
Notifications
You must be signed in to change notification settings - Fork 143
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
Simplify swarm interface #72
Simplify swarm interface #72
Conversation
eb0ce6f
to
357c3cd
Compare
Libplanet.Tests/Net/SwarmTest.cs
Outdated
await swarm.StopAsync(); | ||
|
||
Assert.False(swarm.Running); | ||
await t; |
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.
We would be able (and indeed it's good) to test what if StopAsync()
is called when it's not Running
.
@@ -261,33 +227,32 @@ public void CopyTo(Peer[] array, int arrayIndex) | |||
} | |||
} | |||
|
|||
public async Task DisposeAsync( | |||
public async Task StopAsync( |
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.
I predict that library users will tend to forget to call this after they started a swarm, in the similar way to forget fclose()
in C. How about Swarm
having a finalizer (i.e., ~Swarm()
) and making it to call StopAsync()
with a warning if it's Running
? Python also does a similar thing for file objects.
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.
Since StopAsync()
is an asynchronous function, I'm not sure if it can wait in the finalizer...
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.
Indeed. Make sense. So can we log a warning at least if a Swarm
object is finalized but still Running
?
Blockchain<BaseAction> chain = _blockchains[0]; | ||
Task t = Task.Run(async () => | ||
{ | ||
await swarm.StartAsync(chain, 250); |
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.
As a separated case, it seems good to test if SwarmException
rises when a swarm tries to call StartAsync()
twice (i.e., calling StartAsync()
when it is already Running
).
Blockchain<T> blockchain, | ||
int distributeInterval, | ||
TimeSpan distributeInterval, |
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.
👍
7447aac
to
712f065
Compare
- remove _delta and ProcessDeltaAsync in worker task.
712f065
to
09eb0cd
Compare
Codecov Report
@@ Coverage Diff @@
## master #72 +/- ##
==========================================
- Coverage 86.41% 86.28% -0.13%
==========================================
Files 60 60
Lines 2672 2684 +12
==========================================
+ Hits 2309 2316 +7
- Misses 363 368 +5
|
…0-nightly-20191022 Bump libplanet to 0.7.0-nightly.20191022
…manifests-1667869217 Update manifests [update-rc-v100321-manifests-1667869217]
This PR simplifies
Swarm
's interface as #69. specifically, the following changes have been made.RunAsync()
/DisposeAsync()
toStartAsync()
/StopAsync()
InitContextAsync()
intoRunAsync()
_delta
queue and replace related logic with worker task.