Browse files

README: Add warnings about helper functions

  • Loading branch information...
1 parent 47a1e12 commit 0f192e2fef606afbd1dd76b458c906f7d89a3683 @stuartsierra stuartsierra committed Oct 8, 2012
Showing with 19 additions and 1 deletion.
  1. +19 −1
@@ -230,7 +230,8 @@ Step 5. Restart:
user=> (def my-app (create-application))
user=> (start my-app)
-(You could also combine all those steps in a single utility function.)
+(You could also combine all those steps in a single utility function,
+but see warnings below.)
After that, you've got a squeaky-clean new instance of your app
running, in a fraction of the time it takes to restart the JVM.
@@ -307,6 +308,23 @@ references to things you created in the REPL.
If you create your own instance of the dependency tracker, do not
store it in a namespace which gets reloaded.
+### Warnings for Helper Functions
+Be careful defining a helper function in a namespace which calls
+`refresh` if that namespace also could get reloaded. For example, you
+might try to combine the stop-refresh-start code from the "Managed
+Lifecycle" section into a single function:
+ (defn restart []
+ (stop my-app)
+ (refresh)
+ (def my-app (create-application))
+ (start my-app))
+This won't work if the namespace containing `restart` could get
+reloaded. After `refresh`, the namespace containing `restart` has been
+dropped, but the function continues to run in the *old* namespace.
### Warnings for Aliases
Namespace aliases created at the REPL will still refer to the *old* namespace after `refresh`. For example:

0 comments on commit 0f192e2

Please sign in to comment.