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)
175
questions
41
votes
3
answers
41k
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:
...
36
votes
2
answers
6k
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 ...
21
votes
2
answers
15k
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.
...
13
votes
2
answers
5k
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
1
answer
481
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
1
answer
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
1
answer
2k
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
2
answers
6k
views
C-ifying a capturing lambda
What do you think of this code?
...
10
votes
1
answer
687
views
ActivityLifecycleHelper implementation
Description
The ActivityLifecycleHelper uses wrap(Context)to create the class and save a global ...
9
votes
4
answers
944
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
1
answer
4k
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
2
answers
435
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
4
answers
436
views
Identify Java Callback
I have this common design in my application:
...
7
votes
1
answer
244
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
2
answers
22k
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
1
answer
1k
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
1
answer
403
views
TFunction: std::function replacement for event system
I've been trying to implement delegate for my event system. I thought that maybe std::function can do the trick for me, but it turned out to be not comparable, so what i have end up doing is this - ...
7
votes
1
answer
132
views
Requesting Resources Until Exhaustion
When an API has a 'next' feature, I use the following pattern to obtain all the results:
...
7
votes
1
answer
501
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
1
answer
4k
views
Custom ostream for a println-like function
I am writing a plugin in C++ that uses C API that gives me a single logging function with this signature:
typedef void(*println_t)(const char* text);
I want to ...
7
votes
1
answer
63
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
2
answers
403
views
c++ multithreaded message broadcaster with link lifetime management v3
note: This is v3 of code that was previously reviewed.
I have written a class that handles listeners registering callbacks to receive messages. Link lifetime is managed (or is it? See below). Code is ...
6
votes
1
answer
149
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
1
answer
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
3
answers
1k
views
C++ Generic Callback class with removable listeners by unique id
I'm quite new to the STL.
Does this make sense? Is there a better way of removing the listeners instead of using shared_ptr while keeping the code short and simple? Is there something in the STL to ...
6
votes
1
answer
3k
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
2
answers
72
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
2
answers
210
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
1
answer
163
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
2
answers
489
views
Error Code Stack Trace and Propagation Library in C
I've been programming in Go and I enjoy how easy it is to create descriptive errors and propagate them up the call stack. I wanted that sort of ease and consistency in C so I created a small error ...
6
votes
1
answer
830
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 ...
6
votes
1
answer
214
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
1
answer
3k
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
1
answer
2k
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
1
answer
1k
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 ...
6
votes
1
answer
236
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
1
answer
1k
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
2
answers
315
views
Message Broadcaster
I've written a basic event messenger broadcasting service. This is meant to allow for broadcasting events between loosely coupled areas of code where you may not have or care about a direct reference ...
5
votes
2
answers
3k
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
2
answers
117
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
2
answers
157
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
2
answers
327
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
1
answer
588
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
1
answer
91
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
1
answer
90
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
1
answer
65
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
1
answer
878
views
"Piping" from a callback to an Iterator
My project has a central concept of a Callback<T> which is defined very simply:
...
5
votes
1
answer
6k
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
2
answers
7k
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
3
answers
5k
views
Simple Publisher Subscriber in Java
I am new to Java and had some difficulty creating this simple Publisher Subscriber class. It finally seems to be working and I wanted to check if I have been following best practices and see if there ...