Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

2
votes
3answers
99 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. ...
3
votes
2answers
139 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() ...
-3
votes
4answers
252 views

Might there be two types of a “callback” in programming? [closed]

I know two definitions for a "Callback": A function that is being called-after ("called-back when") a certain event is triggered. A function that is passed to another function as a parameter. An ...
2
votes
1answer
98 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> &...
1
vote
2answers
661 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 ...
0
votes
0answers
72 views

Redirecting the debugger back to user code when stepping through engine code in C++

I have a project (C++, Visual Studio 2015) where I'm thinking of making the API for a library take lambdas or function objects so that the user has a place to put debug breakpoints to know what higher ...
1
vote
1answer
243 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 ...
0
votes
1answer
794 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 ...
0
votes
1answer
635 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) ...
5
votes
4answers
2k 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 (...
3
votes
1answer
103 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 ...
4
votes
2answers
1k 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 ...
5
votes
1answer
388 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 ...
3
votes
2answers
2k 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 ...
2
votes
1answer
204 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()){ ...
0
votes
2answers
464 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....
1
vote
1answer
129 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 ...
0
votes
0answers
57 views

Nested Callbacks: Best Practices for giving access?

A bit of background first: I'm creating a set of Bluetooth Low Energy services (BLEDiscoverer, BLEConnector, BLECommunicator) I'm trying to follow the SOLID principle so I'm putting each class in ...
5
votes
1answer
1k 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. ...
0
votes
2answers
86 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 (...
0
votes
4answers
694 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 ...
7
votes
2answers
589 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 ...
1
vote
2answers
630 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 ...
2
votes
2answers
7k 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 ...
92
votes
1answer
50k 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 ...