Questions tagged [callbacks]

A callback is typically the address of a function or method or lambda expression provided when invoking an API. When an action completes, the expression is executed or "called back". Asynchronous APIs use callbacks to notify the calling function when an operation is complete. Use this tag for questions involving asynchronous APIs requiring a call back expression. Use the tag event-handling for questions on registering or subscribing for events, e.g. GUI.

Filter by
Sorted by
Tagged with
0 votes
1 answer
344 views

Implement Dependency Inversion in C with UML diagram

As per Robert C. Martin in Clean Architecture, he gives a simple UML diagram to illustrate Dependency Inversion. To put it simply, HL1 initially referred to ML1 without interface to invoke F() ...
Andy Lin's user avatar
  • 185
-1 votes
3 answers
550 views

What happens in terms of call stacks when 10000 setTimeouts are called?

Say we call 10000 setTimeouts, each with a random time, each with a few nested timeouts too. What happens in terms of the 1 call stack, or are there multiple call stacks? How does that work? So for ...
Lance's user avatar
  • 2,587
0 votes
2 answers
71 views

Setting custom callbacks in a Javascript applet?

I'm designing a 3D visualisation applet in Javascript. When used, a Canvas will be created and placed inside an HTML element on a webpage, specified by the developer who is implementing the applet. ...
Okarin's user avatar
  • 109
0 votes
1 answer
519 views

Object Oriented Design of Callback Methods

Assume that there is a library and it provides an interface to its users in order to callback them. Users implement this interface and receive notifications from the library. Let's say, ICallback is ...
Ricardo Cristian Ramirez's user avatar
6 votes
1 answer
2k views

What is a "tear-off" in software design or patterns?

What is a tear-off? I ran across the term reading Flutter documentation: Returns a CallbackHandle that can be provided to PluginUtilities.getCallbackFromHandle to retrieve a tear-off of the ...
Pete Alvin's user avatar
4 votes
0 answers
223 views

How to authenticate third-party callbacks that don't support authentication

I'm working on a project that integrates with a third-party service via API, and the third-party uses callbacks to update us on the status of the operations being performed. These callbacks can be hit ...
Omar Rida's user avatar
-2 votes
2 answers
115 views

Should I call a callback for an event triggered by a developer?

I'm designing an API for a stream-processing library. The library will process a stream provided by the user and will transition between states based on the data in the stream. The state transitions ...
awelkie's user avatar
  • 113
1 vote
3 answers
295 views

How to calculate overall progress in independent phases?

When using a call-back to show progress on a multi-phase task, I don't know how to calculate the progress per phase well. One of the phases is collecting data, which differs in size from run to run. ...
virtualnobi's user avatar
3 votes
2 answers
233 views

Callback pattern - return value confusion

I have a ConstraintsResolver class which resolves a queue of Constraints. This is done when a ConstraintsResolver object calls meetConstraint() on a Constraint one. Most of meetConstraint() ...
Themelis's user avatar
  • 139
2 votes
1 answer
115 views

For a use once only button callback, should the name be more related to the button or the task of the callback?

Suppose I have UI like it: <script> var someFunction(){ //some code to validate and then send message } </script> Message:<br> <textarea></textarea><br> &...
ocomfd's user avatar
  • 5,712
1 vote
3 answers
2k views

Callback injection

I have a service that needs to make a callback. Basically, it is an event that is expected to be handled in exactly one place, and that is too important to be optional. The obvious approach seems to ...
Timo's user avatar
  • 382
1 vote
1 answer
720 views

Should I replace switch case of functions determined by options in previous activity?

For example, assume my app has 3 steps with 3 pages: Step 1 : MainActivity: choose color Step 2 : EditTextActivity: input text Step 3 : GreenActivity: display color and input text In ...
ggrr's user avatar
  • 5,765
1 vote
1 answer
4k views

Is it a good idea to use my own callback mechanism instead of standard implementation like startActivityForResult?

I am trying to create a simple app which has 2 activities, which enter text on one activity and then displays it on the title bar if another activity: EditTextActivity: MainActivity: I know the ...
ggrr's user avatar
  • 5,765
1 vote
1 answer
1k views

Best practice to callbacks in OOP (JavaScript)?

For anyone who uses callbacks, how do I approach it when the method is an asynchronous setter? Here's an example class API { constructor() { this.token = null; } refreshToken(callback) ...
Vic's user avatar
  • 171
5 votes
4 answers
4k views

How do I know if my async function is truly asynchronous?

I'm writing a function in the node.js-style asynchronous way, but how do I know if these functions are truly asynchronous, i.e., that they run in parallel and not sequentially? Here is my code (...
chharvey's user avatar
  • 264
2 votes
1 answer
409 views

Is it better to dispatch one event or multiple events for remote calls?

In ActionScript the URLLoader class that has seven separate events than can occur after you call the load() method. In the HTTPServive classes there are two events, fault and result. In one of the ...
1.21 gigawatts's user avatar
5 votes
2 answers
4k views

Library IO: Use Interface classes or Callbacks?

I'm building a smallish library (few kLOC) which processes stream data in C++. From the streamed data (comes in packets) the library compiles a database piece by piece and naturally has to convey that ...
Jan Krüger's user avatar
4 votes
1 answer
659 views

Scala Callback Pyramid of Doom

I would like to solicit some general design principles and best practices to avoid creating a callback pyramid of doom particularly in the Scala language. Consider the following rudimentary and ...
Coder Guy's user avatar
  • 727
3 votes
2 answers
4k views

When to use Future<> vs Listener

I've started working on an existing project (an sdk) at work, and the code base uses listeners like there's no tomorrow. Pretty much every second method takes some sort of listener argument and I have ...
Alex Meuer's user avatar
2 votes
1 answer
547 views

How to clarify the control flow when dealing with many callbacks?

Traditional programming could be done quite readable. Like this: FUNCTION do_HTTP_request(url) { if(!ask_user_if_he_wants_to_connect()) return; if(!network_is_enabled()){ ...
Matthias Ronge's user avatar
0 votes
2 answers
586 views

Blue Giga C++ anti-corruption layer for C callback API?

I'm working with a Blue Giga BLE112 usb dongle. They supply an API in the form of several header & *.c files. It all works off of callbacks. For example. int main() { // defined in a "cmd_def....
RubberDuck's user avatar
  • 8,951
1 vote
1 answer
152 views

What's the proper way to have one active callback at any time?

We have an Android app. The Android App uses Volley (https://developer.android.com/training/volley/index.html) to transmit network data. The point though is not about Volley, is about the pattern ...
dierre's user avatar
  • 211
4 votes
1 answer
2k views

Designing a flexible API with support for Callbacks

I am writing a Java library that needs to make http GET && POST requests. There will be two types of users of this library: Those with understanding of callbacks and know how to use them. ...
Joel Min's user avatar
  • 143
0 votes
2 answers
95 views

JavaScript Callbacks before or after exiting function?

Is there a concrete reason to prefer executing callbacks to functions before or after exiting the called function? Example function doSomethingPossiblyAsync(callback) { if (...
gman's user avatar
  • 532
0 votes
4 answers
2k views

Callbacks without concurrency? [closed]

To sync on the terms I will first give my perspective on what a callback function in the simplest possible terms: A callback function is a function that is executed as a response to a certain ...
TheMeaningfulEngineer's user avatar
7 votes
2 answers
986 views

Ensure that callbacks registration and triggering don't cause infinite recursion

I just spent a long, miserable week debugging a stack-overflow in a C++/Qt application. The fundamental problem was that I had a function that accepted a callback, and in certain cases the callback ...
Kyle Strand's user avatar
3 votes
2 answers
2k views

Publish / Subscribe via HTTP Callbacks?

My team is tasked with creating a publish/subscribe system for incoming REST messages. 99% of the time, this system will be used for notifications between different processes on the same cpu, but we ...
therealmitchconnors's user avatar
5 votes
2 answers
22k views

How should a service communicate with an activity in real-time?

How should a service communicate with an activity in real-time? BroadcastReceivers seem too slow and unreliable. Sometimes they appear too slow or stop working entirely. As an example, there was a ...
David's user avatar
  • 271
99 votes
1 answer
63k views

Is there really a fundamental difference between callbacks and Promises?

When doing single-threaded asynchronous programming, there are two main techniques that I'm familiar with. The most common one is using callbacks. That means passing to the function that acts ...
Aviv Cohn's user avatar
  • 21.4k