MIDRANGE dot COM Mailing List Archive



Home » MIDRANGE-L » October 2012

Re: Callback



fixed

I spend most of my time developing web applications, and I use callbacks all the time to deal with issues caused by asynchronicity.

In the RPG world, if we code:

CALLP RTNA
CALLP RTNB

we expect RTNA to finish before RTNB starts. But in the Javascript world, it doesn't work that way: the code will send a request for RTNA to start and then immediately send a request for RTNB to start, and RTNB could finish while RTNA is still chugging
along. The way around that is to tell RTNA that you want RTNB to start when it's done -- something like CALLP RTNA('RTNB'). One way to think about it is that when RTNA is done, it "calls back" to the original routine to say it's time to start RTNB.

Of course, if you control everything, you could simply code a call to RTNB at the end of RTNA, but many times you don't -- a good example is AJAX calls -- and that's when callbacks become essential ....


Just another perspective ... :-)

Midrange Systems Technical Discussion <midrange-l@xxxxxxxxxxxx> writes:
John

As I wrote my reply, I was thinking about whether we can specify the
address of a procedure in another service program, say. I didn't bring
it up, because I wasn't sure, and I thought it'd confuse the issue.
Generalizing to that would have benefits similar to what we espouse
already for service programs.

I'll still go with the callback term - I could even say that the called
party is calling back to someone known to the calling party. It does
seem to get a bit precious, however, and the traditional understanding
works for me, although I hear what you are saying.

Vern

On 10/15/2012 5:33 PM, John Yeung wrote:
On Mon, Oct 15, 2012 at 5:46 PM, Vernon Hamberg
<vhamberg@xxxxxxxxxxxxxxx> wrote:
The easiest example I use - the almost-only-one, actually, is when I use
the qsort API - when you call qsort, you tell it what data is to be
sorted, how long each element is, and a pointer to a procedure that will
compare 2 elements and return either that they are the same or that one
or the other is larger. That procedure is the callback - maybe we can
think of it as a CALL BACK to the caller of qsort. qsort walks through
the elements and passes pairs of them to the callback procedure.
I have never really liked the explanation that the called function is
"calling back" to the original caller. Yes, that's where the term
came from, but I don't think it emphasizes the right things.


Mike Naughton
Senior Programmer/Analyst
Judd Wire, Inc.
124 Turnpike Road
Turners Falls, MA 01376
413-676-3144
Internal: x 444
mnaughton@xxxxxxxxxxxx
****************************************
NOTICE: This e-mail and any files transmitted with it are confidential and solely for the use of the intended recipient. If you are not the intended recipient or the person responsible for delivering to the intended recipient, be advised that any use is
strictly prohibited. If you have received this e-mail in error, please notify us immediately by replying to it and then delete it from your computer.






Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2014 by MIDRANGE dot COM and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available here. If you have questions about this, please contact