Skip to content

How to deal with async code in state start #118

@jpmonettas

Description

@jpmonettas

Hi, I'm using mount in ClojureScript and I'm having a hard time figuring out how to deal with async code inside a state start.
How does component B that depends on A knows A is ready when A start code is async?

I have something like:

(ns server.db)

(defstate db
  :start (let [conn (create-db-connection)]
           (create-tables conn (fn []
                                 ;; here I know tables are created
                                 ))
           {:conn conn})
  :stop ...)

(ns server.syncer)

(defstate syncer
  ;; how can I synchronize this so I'm sure
  ;; this component is started when db component has finished starting
  :start (insert-some-stuff-in-db (:conn @server.db))
  :stop ...)

Thanks!!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions