Questions tagged [callback]

A callback is a piece of code (i.e. the address or reference of a function or method or a lambda expression) that is passed as an argument to other code, which is expected to call back (execute) the argument at some convenient time. This tag should be used with questions about an API that uses call backs to notify the caller when an action is complete. Use the event-handling tag for questions involving subscribing to events such as in a GUI framework.

In computer programming, a callback is a piece of executable code that is passed as an argument to other code, which is expected to call back (execute) the argument at some convenient time. The invocation may be immediate as in a synchronous callback or it might happen at later time, as in an asynchronous callback.

Wikipedia article: http://en.wikipedia.org/wiki/Callback_(computer_programming)


An example of sync process callback in javascript:
function outer(argumentOne, fn){
    console.log("what was argumentOne? ", argumentOne);
    return fn();
}

function someCallback() {
    console.log("callback triggered!");
}

outer("brown", someCallback);

An example of async process callback in javascript:

function mySandwich(param1, param2, callback) {
        console.log('Started eating my sandwich.\n\n It has: ' + param1 + ', ' + param2);
    setTimeout(function(){
        callback(null,param1*param2);},2000);
    }

    mySandwich(1, 2, function(err,result) {
        console.log('Finished eating my sandwich.' + result);
    });

Output:

Started eating my sandwich.

It has: 1, 2
Finished eating my sandwich.2
18062 questions
4
votes
1 answer

How to pass an argument in useCallback hook?

I'm trying to use the useCallback hook, to change the language using gatsby-intl plugin, they have a method (changeLocale()) what can be used to change the default language of the site. I wanted to avoid passing props in JSX arrow's functions…
Ferran Buireu
  • 28,630
  • 6
  • 39
  • 67
4
votes
5 answers

C++ : How to pass function pointer, stored in a local variable, as a template parameter

using namespace std; float test1(float i){ return i * i; } int test2(int i){ return i+9; } struct Wrapper{ typedef void (*wrapper_type)(int); template void wrap(string name,R (*fn) (A) ){ …
Code freak
  • 695
  • 2
  • 8
  • 19
4
votes
2 answers

What is a good definition of a "userdata pointer"?

I have searched for a good explanation but can't find one. I could try to write one myself but I'd prefer if someone with better english could help me explain this for Zan Lynx in the comment here. ...and it seems like there should be a good…
epatel
  • 45,805
  • 17
  • 110
  • 144
4
votes
1 answer

Redirect to frontend URL with POST after external payment

My VueJS application relies on a Java backend. This Java backend serves all REST endpoints for providing the data. When a user performs a checkout the backend responds with a redirect url and redirects the user to that URL. This is done simply like…
Robert Strauch
  • 12,055
  • 24
  • 120
  • 192
4
votes
1 answer

What would be the benefit of an interface which implies a certain implementation?

I'm looking at this: public interface IAjaxCallbackEventHandler : ICallbackEventHandler { string CallbackResponse { get; set; } } } So pages implement this interface and end up looking like this: public partial class XPage : Page,…
Cade Roux
  • 88,164
  • 40
  • 182
  • 265
4
votes
1 answer

Not received success callback with android plaid sdk in Android

I implemented plaid sdk in my android app with version - 0.3.0 I not received success or any callback after click on last screen "Continue" button. After click on "Continue", I got callback with onActivityResult() with resultCode=0 but not related…
Keyur Android
  • 375
  • 2
  • 6
  • 20
4
votes
2 answers

How to access the training and testing data within a callback in tensorflow?

> import tensorflow as tf > > class MyMetric(tf.keras.callbacks.Callback): > def on_epoch_end(self,epoch,logs={}): > # how to access X_train and X_val here > > ... > …
tudor.a
  • 49
  • 3
4
votes
1 answer

Gulp: call an async function which provides its own callback from within a transform function

I want to create a function for use in a pipe() call in Gulp that'll enable conversion of xlsx files to json. I had this working with NPM package 'excel-as-json' for gulp 3, however Gulp 4 has forced me to actually understand what it is doing ;-)…
MattV
  • 1,353
  • 18
  • 42
4
votes
1 answer

Callbacks are not getting triggered while using Steamworks.NET wrapper

I am trying to get around and understand how to properly use Steamworks.NET C# wrapper as I want to use it with my discord bot. Now, most of the functions work, which uses normal callback methods. I got into a wall when I was trying to use three…
Gromis
  • 127
  • 1
  • 20
4
votes
5 answers

How to declare a function callback that accepts multiple parameters in Dart/Flutter?

final ValueSetter setVal; can be assigned a function callback that accepts one parameter like setVal=(i){ //assign i to some variable } What if I wanted the callback to accept 2 parameters like setVal=(i,j){ …
Michel Thomas
  • 143
  • 1
  • 10
4
votes
4 answers

Pass any member function of any class as a Callback function

I'm working on a OpenGL menu which contains some buttons. I want to be able to associate an action (member function (with a fixed signature) of any class!) to a button which gets executed when the button is pressed. I can do it right now but only…
4
votes
3 answers

Is it possible to define a function using a callback type definition?

I'm interested in defining a function using a predefined callback type. Let's assume I have defined callback type: typedef BOOL (*is_trigger_required_cb)(void); Now I would like to declare and define a function using the above type. I would like to…
Morinho
  • 65
  • 9
4
votes
1 answer

How to access and update Bokeh plots or widgets using an external JavaScript code?

I have a Bokeh plot which is controlled by a time Bokeh slider. I am trying to set the time of the slider and the corresponding plotted data to the current time of the browser by clicking on a button. I know how to do the same thing if everything…
4
votes
3 answers

Is there any way to pass a block argument in Python without defining it as a function first?

in Ruby, a block argument works like this: def foo_bar (&block) block.(4) end foo_bar do |x| puts x puts x * 2 end =begin 4 8 =end I've seen the following equivalent in Python, but I find it quite unsatisfactory, because it requires…
Sapphire_Brick
  • 1,560
  • 12
  • 26
4
votes
1 answer

WCF Notify subscribers asynchronously

This is my WCF service. I want to notify multiple subscribers of some updates and do it asynchronously. How do I do that? // Callback contract public interface IMyServiceCallback { [OperationContract] void Notify(String sData); …
Pratik Deoghare
  • 35,497
  • 30
  • 100
  • 146
1 2 3
99
100