Terminate tern worker on quit

This fixes issue #7683.
Good point! I forgot to add @param since I was in a rush to set up the pull request for others to discuss. So don't land it yet even after I make the changes. Thanks for reviewing.