Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a callback?

Is it a function?
Is it a function being called from the source?
Or, is it a function being returned from the destination?
Or, is it just executing a function at the destination?
Or, is it a value returned from a function passed to the destination?

like image 336
qstar Avatar asked Nov 27 '22 15:11

qstar


1 Answers

A callback is the building block of asynchronous processing.

Think of it this way: when you call someone and they don't answer, you leave a message and your phone number. Later on, the person calls you back based on the phone number you left.

A callback works in a similar manner. You ask an API for a long running operation and you provide a method from within your code to be called with the result of the operation. The API does its work and when the result is ready, it calls your callback method.

like image 197
diciu Avatar answered Dec 19 '22 23:12

diciu