How to stop method from executing with code
===

I have a method in my controller which I call with ajax.
The method can be called VERY often (depends on the speed of typing of the user).
The user types letters, words. I want the method to be called once the user stops typing.

The parameter of the method is the written text by the user.

In my way, the method gets called a lot of times in a small amount of time.

Is there a way to call the method always (after each letter) but then the method to stop executing immediately if it is called right away?

Example: a user will write slowly 10 letters - the method will be called 10 times.
Example: a user will write fast 10 letters - the method will be called the 10th time OR the method will get called 10 times but will stop executing the first 9 times and finish executing only the 10th time