Fork me on GitHub

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?


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


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


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


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


@surreal.analysis: we do have an open discussion about failures on start:


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


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


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