If you need to maintain an association between buffer and some long-running process in Emacs, sesman is very good for it.

It saved me a lot of boilerplate code.

github.com/vspinu/sesman

P.S. The documentation is lacking, but take a look at test, CIDER, or emacs-arei.

#emacs