Based on the discussion in these two comments:
At the moment the Initializer type is overly complex in its usage. It is designed to be re-used, when it doesn't need to be and over-uses channels and go routines. The type can be simplified in the following manner:
- Simplify
Initializer by making it non-reusable; besides tests the type isn't used in this manner anyway
- Remove
Reset(): it is only used in tests and the directory used by Initializer is known to the caller. In tests the caller can delete the directory itself. In Production this shouldn't be done anyway; switching identities should instead use a different datadir for PoST.
- Remove
SessionNumLabelsWrittenChan(); there is no need for this method when SessionNumLabelsWritten() returns the same information in a synchronous way. Callers interested in updates should rely on the values returned by the second method and the status from Started(), Completed(), isInitializing() or even a new single method that combines the purpose of all 3.
Initialize() should take a context as parameter and instead of Stop() callers should just cancel the context they passed in.
Refactorings of types using Initializer in go-spacemesh:
PostSetupManager:
StatusChan() should just call SessionNumLabelsWritten() and return the status directly instead of via a channel
SmesherService:
PostStetupStatusStream() should instead of relying on receiving values in regular intervals via the channel, call the (new) synchronous method in PostSetupManager in regular intervals.
Based on the discussion in these two comments:
At the moment the
Initializertype is overly complex in its usage. It is designed to be re-used, when it doesn't need to be and over-uses channels and go routines. The type can be simplified in the following manner:Initializerby making it non-reusable; besides tests the type isn't used in this manner anywayReset(): it is only used in tests and the directory used byInitializeris known to the caller. In tests the caller can delete the directory itself. In Production this shouldn't be done anyway; switching identities should instead use a different datadir for PoST.SessionNumLabelsWrittenChan(); there is no need for this method whenSessionNumLabelsWritten()returns the same information in a synchronous way. Callers interested in updates should rely on the values returned by the second method and the status fromStarted(),Completed(),isInitializing()or even a new single method that combines the purpose of all 3.Initialize()should take acontextas parameter and instead ofStop()callers should just cancel the context they passed in.Refactorings of types using
Initializerin go-spacemesh:PostSetupManager:StatusChan()should just callSessionNumLabelsWritten()and return the status directly instead of via a channelSmesherService:PostStetupStatusStream()should instead of relying on receiving values in regular intervals via the channel, call the (new) synchronous method inPostSetupManagerin regular intervals.