Terminate tern worker on quit

This fixes issue #7683.
in this function, perhaps, the param should be called `terminate` or something like this. also, add `@param` to the doc.