Add a safety check to prevent an infinite loop.
Ensure the process exits after the prompt is generated.
Correctly check if a process is running.
Improve control flow when updating the global cache.

* Return errors instead of throwing them.
* Ensure the lock process is set before updating.
Merge pull request #40 from Impromptu/stop-hanging

Improve control flow when updating the global cache and generating a prompt.