Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

Questions tagged [callback]

Callback is facility to save a piece of code so that it may be invoked later in the current environment (Typically in response to an event)

Filter by
Sorted by
Tagged with
34
votes
2answers
5k views

Asynchronous network callback code

I did not get the job after submitting this piece of work in an interview, but I have no feedback to know what "BAD" things are inside this block of code. The requirements are: Connect to the ...
19
votes
2answers
13k views

C++ Observer design pattern implementation

I'm using the Observer design pattern in order to manage events in the game I'm currently developing. I based myself on the implementation demonstrated here but improved it in order to ease its use. ...
15
votes
3answers
8k views

Partitioning an array based on a condition in Javascript

Using the array.filter function, I can efficiently pull out all elements that do or do not meet a condition: ...
12
votes
2answers
988 views

Implementation of a Thread Pool in C++

I wanted to implement a thread pool to test my knowledge of various modern C++ features. The end result could be better, but I need a review as I'm not sure about delicate things especially regarding ...
12
votes
1answer
374 views

Pledge: Promise-like entities design goals experiment

Background I was writing a promises/a+ implementation, just for fun. About halfway through I decided it wasn't that fun after all, so I decided to do something a little different. Thinking of ...
11
votes
1answer
2k views

C++14 Event System

I've created a simplified event system for C++14. The code is commented, so it shouldn't be hard to read. There's also a simple usage scenario below. It is still a work in progress and uses some not-...
11
votes
1answer
1k views

Callback in Linux kernel driver in order to hide device's low-level protocol

I'm am writing a Linux kernel driver for HD44780 LCDs connected via I2C bus. In my last change I tried to decouple low-level code (which talks to the device via I2C) from device's logic (printing ...
10
votes
1answer
563 views

ActivityLifecycleHelper implementation

Description The ActivityLifecycleHelper uses wrap(Context)to create the class and save a global ...
9
votes
4answers
725 views

ViewModels Mediator with multiple generic callbacks

I'm developing a mediator for an MVVM application. This application lets employees file tickets with IT support to ask for help. The mediator communicates messages and triggers callbacks between ...
9
votes
1answer
2k views

Simple callback wrapper for an embedded C++ app

I'm writing a callback wrapper class for an embedded application in C++11. The basic idea of the class is to be able to use it as a replacement instead of C-style callback functions, with the added ...
8
votes
2answers
4k views

C-ifying a capturing lambda

What do you think of this code? ...
8
votes
2answers
381 views

Concurrent Task Waiter 2

This is an iteration of my previous question: Concurrent Task Waiter Summary from before: I have some code designed to simplify managing multiple asynchronous operations. The code creates ...
7
votes
1answer
241 views

Do nothing lamda…

$privilegeStrings = array_filter($privileges, function ($s) { return is_string($s); } ); Is there a better way to specify that I want just the string values in ...
7
votes
2answers
19k views

Callback on AlertDialog

I am using an AlertDialog in Android, asking the user for some input. I would like do run some code when the user has finished entering her input. Since an ...
7
votes
1answer
690 views

Simple helper for making things “disposable”

I often write small classes to make undisposable things disposable so that .NET can handle something automatically, like stopwatches or logs. I thought why not write a small helper that can be used ...
7
votes
1answer
124 views

Requesting Resources Until Exhaustion

When an API has a 'next' feature, I use the following pattern to obtain all the results: ...
7
votes
1answer
461 views

Prime Numbers Store

Let's say we need to create a store for selling prime numbers. Users enter the store and ask to buy a number. If the number asked is a prime number, 1.1. then it's either available for sale 1.2. ...
7
votes
1answer
57 views

Apply arbitrary action during recursive generator function

I've got this recursive generator function. It will traverse an object looking for "leafs", any keys that don't point to sub-objects. Then it applies one of two actions on the leaf and yields it. Any ...
6
votes
4answers
389 views

Identify Java Callback

I have this common design in my application: ...
6
votes
1answer
90 views

C# asynchronous notification vector

The purpose of this class is to efficiently notify another thread when data is available with minimal blocking to access/pass the data. The data reader/producer thread processes data in bulk which ...
6
votes
1answer
6k views

Node.js callback error pattern

The errors are passed through every callback, but in fact, it might be better to throw an error at higher levels. For example, look at the mongodb.js database function. It passes through an error in ...
6
votes
1answer
2k views

Simple implementation of signals and slots mechanism using templates

I tried to implement a simple signal&slots mechanism for some DSP software that runs on embedded Linux. I would like if somebody can review this code and give me some guidelines. Any review and ...
6
votes
2answers
69 views

Alternate way for comparison call back function?

I'm doing a programming practice problem and was wondering if someone can suggest a better to create/setup the call back for the comparison function. I have the following classes: ...
6
votes
2answers
189 views

Is this the right way to work with callbacks and the EventEmitter?

I'm creating a small online multiplayer game in NodeJS and I'm wondering if I'm "doing it right". Here is a bit of my code: ...
6
votes
1answer
152 views

replaceWithCallback() UDF

As explained in my blog article… I was looking up the docs for Javascript's String replace() function the other day (because, no, I could not remember the vagaries of its syntax!). And whilst ...
6
votes
1answer
1k views

Hooking with Python3 Decorators

I wrote this prototype after reading the Wikipedia article on hooking. I didn't bother to read any of the code examples listed there because, well, I just didn't. I don't have a good excuse. The ...
6
votes
1answer
160 views

Processing input in background while user is typing

Use case A GUI with 2 controls: An input control for text (a DNA sequence) that should be analyzed A result control that displays the analyzing result of the entered text The analysis takes 2-3 ...
6
votes
1answer
2k views

Callback functions to select the tab to the left in Google Chrome

I'm a JavaScript rookie, but I wrote a JavaScript function as part of a Chrome extension that will activate the tab to the left of the currently active tab. The function is pretty ugly, but I couldn't ...
6
votes
1answer
157 views

Rate limiting function calls

I wanted to write a function that when applied to another would rate limit it, but permit all calls to eventually make it through. Comments and criticism welcome. ...
6
votes
1answer
943 views

MVC Model validation callback

I have made a simple MVC framework of my own for my personal website to learn a thing or two about how this whole thing even works. I think I've got the idea, but there's one thing I'm not sure about. ...
5
votes
2answers
2k views

Synchronization in an event manager

I'm working on an event manager, and I am wanting it to be a tool developers use. It is lightweight and it uses annotations to register events. I've tried to set up ...
5
votes
2answers
105 views

Event emitter npm module

I was asked to complete the task described below: Event Emitters are objects that serve as the core building block in event-driven architectures. They simplify the process of handling asynchronous ...
5
votes
2answers
196 views

Swapping dynamically populated images on hover/touch

I'm using jQuery to swap images on hover. There's a main image, and a gallery of thumbs. When the thumb is hovered over/touched, the larger version of it populates the main image, and the smaller ...
5
votes
1answer
579 views

Avoiding callback chaining in authenticator

I'm developing an iOS Application in Swift that uses Google Cloud Endpoints as its backend. For now, I've just written the code for the user to login with his Gmail account and I've refactored it as ...
5
votes
2answers
97 views

Simple replacement for Redux in ES6

The idea about this code is that it's a full replacement of Redux — in 22 lines of code. ...
5
votes
1answer
719 views

Python model for a “snake”-like game

I wrote a python model for the game "snake" that I'm not really satisfied with. My intention was to separate the game logic from the drawing and input handling (which worked quite well) but I've got ...
5
votes
1answer
72 views

Process chain approach

I've been researching about JavaScript and jQuery function chaining and different callback techniques. I am trying to create a very generic code that allows chaining, and in a way that I may create ...
5
votes
1answer
76 views

Function to foreach over an array

I made a very simple generic function to foreach over an array in C using a callback function: ...
5
votes
1answer
851 views

Request and callback design

I am just trying to improve my coding and designing skills in C++ and for that I am trying to solve same age old problem of mapping a http request to method. Could you guys please look at my program ...
5
votes
1answer
62 views

Organize JavaScript for video player controls

I have a small piece of code, and the problem is that I don't know how to organize it. There are tons of tutorials about JS code organization but I feel that those are for large scale apps. Also, I'm ...
5
votes
1answer
5k views

Remove an event listener after firing once or any number of times

Remove an event listener after firing once or any number of times This is what I have: ...
4
votes
2answers
4k views

Flattening multiple nested node readline questions

Say I'm creating a simple CLI. I want to use native node readline module to take in some input from user at prompt. I thought of this: ...
4
votes
1answer
186 views

A method for events callback with the correct “this”

What do you think of the following "utility" : ...
4
votes
2answers
13k views

Generic callback object, but I need the type parameter inside methods

Inside my android app, I currently have methods that look like below code. Since they all need a callback object that basically does the same thing and I would like to try to eliminate the duplicated ...
4
votes
1answer
3k views

Collection of Actions

I am trying to create a class to queue up a series of commands. (Not really a queue as events happen based on time). Each command has a callback (Action) that get's called. However, each Action has a ...
4
votes
2answers
942 views

C++ EventHandler class, invoking & arguments

This is my EventHandler class, which is extremely simple and can be used on lambdas and similar: ...
4
votes
1answer
100 views

Constraining a property setter fluently

The below code is aimed at providing you the most amount of control and flexibility with control which value gets set to a property. I Introduce to you, the ...
4
votes
1answer
909 views

Simple event dispatcher

Here is my very first event dispatcher. I would like to get both, style and code review, as well as some ideas to improve this implementation (new features etc.) I tried to write code in C++17 style ...
4
votes
2answers
109 views

Initialising accounting groups

This deeply nested set of callbacks is very unreadable and I'm looking for ways to improve it: ...
4
votes
1answer
2k views

Fast templated call back implementation

Below is the code for my templated callback implementation. Currently it works for a single parameter. One thing I was going to try and do next was increase the argument to the function from 1..N ...