Answer:
The best thing to do in each of these situations is to be polite, quick, and honest.
Explanation:
For the friends one you can say:
Well, I have to go now, but maybe we can talk some other time, okay?
For the work one you can say:
Thanks for telling me all the info, but I need to get back to work. Maybe we can talk more during break time.
You don't want to be too mean when ending the conversation.