Fork me on GitHub
#mount
<
2016-08-16
>
surreal.analysis20:08:56

Currently running into an issue with mount: I have a setup similar to the first example in the README:

(defstate conn :start (create-conn)
               :stop (disconnect conn))
However, create-conn might fail. In those cases, we log the issue, and return nil. However, mount sees that (create-conn) returned, and sets conn to the started state. When trying to stop conn, we see an exception because disconnect is a method provided by a protocol (we’ll call it IConn), and conn, being nil, obviously doesn’t implement that. I can fix this with a simple stopgap by saying something like (when conn (disconnect conn)), but I’d prefer a way to signify to mount that the connection wasn’t actually started. Is there a way to do this?

dm320:08:11

how do other states that depend on conn function if it's not started up?

surreal.analysis20:08:38

They don’t, because they don’t function if conn is nil

surreal.analysis20:08:22

I suppose just throwing an exception would be the simplest actual solution for what I want, which is that the world should stop and mount shouldn’t start up

dm321:08:06

if there's no sensible way to recover - no point in doing anything

tolitius21:08:58

@surreal.analysis: we do have an open discussion about failures on start: https://github.com/tolitius/mount/issues/50

tolitius21:08:11

but I agree, :start just takes a function, if the function fails, it should throw, and if it does that mount won't start the state

tolitius21:08:06

it is a bit simpler to delegate what's needed to an application function rather than a mount one, since this application could / should drive what is needed

tolitius21:08:04

it could be just an exception, or some kind of a retry logic, or a default, etc.. application would know that a lot better than mount