A good way is to end the conversation yourself.
Say niceties such as that it was good to have met (it's a signal that you want to end this conversation), walk a few steps and smile (try not to look grumpy or negatively) and then wish the other a good day and say good-bye... or whatever you say before you leave.
The other way is more tricky. I'm not sure if what I know is any helpful to you.
If a conversation is ended by the one you're conversing with, there're usually signals as well. The sentences may become shorter than earlier in the conversation and the speech is suddenly faster. They may give more generalised than detailed answers. They might also say it was good to have met you, good to have seen you or that they want to do this and this and this today/later/now. They might tell you to deliver regards to someone.
Additionally, their body language changes. They may shift their weight from one feet to the other. Or they turn around, away from you or fully towards you (it can be either, and turning towards you can also mean the opposite, so this is tricky). If they have something in their hands, they may start to fiddle with it or alternatively attempt to continue what they were doing before you met them.
Pay attention to whether they're nodding rather than talking a lot (if they talked a lot earlier in the conversation). It might mean they don't want to start a new topic and just get over with it and leave.
Pay attention also to some gestures such as if pushing an invisible person away half-heartily. Or if they're doing a winking gesture (which is an obvious sign that the other wishes to part now).
Usually, people try to look really nice and friendly before they say good-bye. They might start to smile and laugh a lot and nod and say niceties.
If you meet with a person because of a specific reason, many of the above rules apply. But on top of it is that the content of your conversation plays a huge role. You must keep track of whether you talked about everything that you ought to talk about. Best way is to ask if there's something else or whether that#s all. If they say yes - well, you know you can leave then!
A dead-give-away is the awkward silence... in that case, it's better to spontaneously say that you'll leave, say good-bye, wish the person a good-day and leave (not too fast!). But do not wait too long, don't wait and consider whether this conversation really is over or not, unless you don't mind feeling awkward.
If they really want to add something - they'll call after you. And then you might just turn around on the spot, look friendly and open (try not to look panicked or worried!) and ask what they want to say. That way it's not awkward.
If you just stay friendly and keep a laugh on your side, it won't be awkward at all.
Anyway... that's what I do.
_________________
Autism + ADHD
______
The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it. Terry Pratchett