Open michaelsbradleyjr opened 3 years ago
Updated the details above after giving them more thought.
To prevent forcing implementing clients from having to run stop
, disconnect
, and logout
, we should consider a public api convenience proc that does all three, is async, and returns an error result.
Related to the concerns in #300.
My proposal:
api/common.nim
, add an enum:proc new*(T: type StatusObject, ...)
so that it causes no side-effects, only instantiatesStatusObject
, withrunState
field set tounstarted
. Since it would not cause any side-effects, it would not need to return the instance wrapped inResult
, just the instance itself.start
andstop
procs:proc start*(self: StatusObject)
should cause side-effects, e.g. initializing/openingaccounts.sql
and finally settingself.runState = RunState.running
. It should not involve invocation ofself.login()
orself.connect()
: those are distinct operations that a user of the library (client implementor) is in the best position to decide when they should be called. However,if self.runState != RunState.unstarted
, thenproc start
shouldraise areturn an error result, and it should be documented thatDefect
proc start
should only be called oncecan be called successfully only once.proc stop*(self: StatusObject)
should cause side-effects, e.g. closingaccounts.sql
and finally settingself.runState = stopped
. It should not involve invocation ofself.disconnect()
orself.logout()
: those are distinct operations that a user of the library (client implementor) is in the best position to decide when they should be called. However,if not (self.networkState == NetworkState.disconnected and self.loginState == LoginState.loggedout and self.runState == RunState.running)
, thenproc stop
shouldraise areturn an error result, and it should be documented thatDefect
proc stop
should only be called oncecan be called successfully only once, e.g. in a context leading directly to program exit.All public API procs should
raise areturn an error result ifDefect
self.runState != RunState.running
, except forproc start*(self: StatusObject)
, and of courseproc new*(T: type StatusObject, ...)
.