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
1 vote
2 answers
71 views

Class that provides callback execution at a specified rate

Here is a class I wrote to provide a user a way to have a callback function executed at some defined frequency: Task.hpp ...
Clay Brooks's user avatar
2 votes
1 answer
542 views

Extracting data from vue-chartjs into an array of datasets

I have a function which returns an array of datasets for a chart written with vue-chartjs. The getter getChartData returns an array with three objects with nested ...
Olga B's user avatar
  • 155
2 votes
0 answers
60 views

Controller to execute AJAX requests for a client

I have been developing this structure or pattern (I don't really know how to call it). It's my first time doing something like this, and I'm a bit worried about the future, if it becomes unmanageable. ...
Vistor's user avatar
  • 43
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 ...
Nenad's user avatar
  • 63
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 ...
Letharion's user avatar
  • 618
2 votes
1 answer
333 views

Make HTML/Javascript Geolocation function more linear

I'm checking users locations with HTML Geolocation before unlocking the front door. Geolocation takes a few seconds in addition to the time it takes the user to approve it, so currently I have a ...
Patrick Stetz's user avatar
2 votes
2 answers
1k views

addEventListener after fetched data

This is working code, but I want to simplify, correct, and improve the code. ...
user348246's user avatar
4 votes
1 answer
2k views

Callback pattern for handling socket response

I am in the process of learning go and am coming from a PHP, JS, and Nodejs background. I created a package that is a client which connects to a socket server and processes the data received from ...
kyle's user avatar
  • 183
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 ...
IS4's user avatar
  • 171
1 vote
1 answer
59 views

Poké-permalinks

On Pokemon Fusion, I found it annoying that the webpage didn't automatically update the tab URL to the permalink when the fusion is changed, so I decided to write a UserScript to do that. After ...
Patrick Roberts's user avatar
2 votes
1 answer
225 views

HMAC Middleware

I have been programming a middleware for my small application that verifies if an authentication header is present and verifies the HMAC present in it. I would like to know what I could optimize in ...
TomasLife's user avatar
3 votes
1 answer
4k views

Nested loop with synchronous and asynchronous behavior

The problem is as follows. I have an array of objects like so: ...
Priyath Gregory's user avatar
0 votes
1 answer
58 views

Running arbitrary number of mongo queries in nodejs

I am faced yet again with a callback headache: Simply I need to return to the client the results of multiple mongo queries, the number of which I don't know in advance. In short: fetch the first ...
neric's user avatar
  • 103
3 votes
1 answer
2k views

Use callback style to start a worker thread and receive result in Qt

After using JavaScript for a while, I think callbacks are pretty good for asynchronous programming, but I haven't seen anything similar in C++. What I want to achieve is to start a worker thread from ...
Snowfish's user avatar
  • 103
2 votes
2 answers
390 views

Read lines from file, calling a consumer function for each line

I wrote a function for iterating over a large file with performance in mind. It takes in an InputStream and reads until it reaches the end of the file. Whenever it ...
LapisSea's user avatar
3 votes
0 answers
570 views

C++ regex_replace with arbitrary function

This is a version of C++17 regex_replace that handles arbitrary functions to do the replacement, instead of using regex_replace'...
Quuxplusone's user avatar
  • 19.3k
1 vote
1 answer
2k views

C++ event system

I created a simple C++ event system. In my code Event_channel is a static class that wraps singletons that manages events per event type basis. Every singleton ...
Lesley Lai's user avatar
3 votes
1 answer
180 views

TimeoutManager: check whether a task has been finished within a given time

I want to make a helper class, which raises an event whenever something is not finished in a certain time. Example: my program sends out multiple network messages concurrently. After a random delay, ...
HugoRune's user avatar
  • 339
0 votes
1 answer
49 views

Implementation of callback in database request

I am a complete beginner in JavaScript / Node.js / Express, but have some experience with php. I am trying to pass data from a SQLite database to the console. In my previous attempts, ...
Max's user avatar
  • 241
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 ...
Queder's user avatar
  • 255
0 votes
2 answers
259 views

Callback notation in a Mediator [closed]

I'm implementing a Mediator and I'd like to simplify the callback notation a bit. My mediator has Register and Notify methods : ...
Queder's user avatar
  • 255
3 votes
0 answers
58 views

Nisse Server: Part 5 Handler

Getting close to a release of generic server. Nisse Server: Part 1 Helper Functions Nisse Server: Part 2 Socket Layer Nisse Server: Part 3 Stream Layer Nisse Server: Part 4 Server As I mentioned ...
Martin York's user avatar
  • 94.3k
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 ...
JanDotNet's user avatar
  • 8,538
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: ...
Max Rosett's user avatar
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: ...
PointerToConstantChar's user avatar
3 votes
1 answer
89 views

Function that calls a function with the terminal temporarily set to raw mode

I'm working through Build Your Own Text Editor, a walkthrough of the code to an extremely small text editor for a posix terminal in C, but I'm attempting to follow along in-the-spirit with OCaml. I'...
Jon Raphaelson's user avatar
2 votes
1 answer
635 views

Event Handler Registration in Java [closed]

I have a stateful object on which I'd like client code to be able to register many event handlers. These handlers have different signatures—they usually accept the originating object and some piece of ...
John Dorian's user avatar
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 ...
t3chb0t's user avatar
  • 44.1k
3 votes
0 answers
278 views

Simple C++11 Subject-Observer

Building on the answer in C++ class member callback simple examples, I've tried to put together a simple subject-observer pattern without needing to inherit a virtual Observer class. I also wanted to ...
rsjaffe's user avatar
  • 253
4 votes
2 answers
118 views

Initialising accounting groups

This deeply nested set of callbacks is very unreadable and I'm looking for ways to improve it: ...
Vishal's user avatar
  • 197
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 ...
Neeraj Kumar's user avatar
1 vote
1 answer
125 views

Using JavaScript callback to conditionally send email

I have an app where users at some point select the amount of tasks they have completed. If they have only completed 3 or less then 3 tasks then I send an email to the system admin to inform them. But ...
Lorenzo von Matterhorn's user avatar
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 ...
Venemo's user avatar
  • 233
2 votes
1 answer
895 views

Callback class to callback member (virtual) functions

After looking at a post on CR I found that pointers to member functions are incredibly hard to use, especially as callbacks. The current solution doesn't solve the problem mentioned in the linked post,...
Incomputable's user avatar
  • 9,374
2 votes
1 answer
2k views

async.waterfall call

Does anyone have any recommendations for how I could make this async.waterfall call neater? Ideally I'd be able to do something like: ...
David Tamrazov's user avatar
10 votes
1 answer
687 views

ActivityLifecycleHelper implementation

Description The ActivityLifecycleHelper uses wrap(Context)to create the class and save a global ...
Jon Merritt's user avatar
-1 votes
1 answer
3k views

Example of Callback Hell [closed]

I am trying to come up with a minimal example of what is known as callback hell in JavaScript (so this would be a bad code review I guess). This is what I have so far, and I would like it to also run ...
Keno's user avatar
  • 117
3 votes
2 answers
859 views

Callback system for events in a window

I have written a simple window event capture wrapper that gets events that happen to the window, and can be checked anywhere in the program through a global class. I wanted to be able to create a ...
TCVM's user avatar
  • 33
1 vote
2 answers
993 views

Avoiding nested callbacks when using MongooseJS

I'm diving into the world of nodejs and mongo. I am playing around with a simple app that uses MongooseJS to talk to Mongo. I have been looking at examples and some GitHub projects for references, but ...
user avatar
0 votes
1 answer
950 views

JavaScript multiple ajax calls but can either be one or two

I'm writing a piece of JavaScript to make one or two ajax calls. There will always be one ajax call fired but it might be two based on cookie setting. If user is logged in then we call another service ...
toy's user avatar
  • 831
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 ...
alexwc_'s user avatar
  • 249
3 votes
1 answer
390 views

From Callbacks to Promises - MEAN Stack

I have a MEAN Stack app in which I have been using mongoose routes to update my data. Some of those routes have a lot of back and forth in terms of updating data across multiple users and collections. ...
Lorenzo von Matterhorn's user avatar
2 votes
1 answer
138 views

Input-reading library for Node.JS

Recently I have been busy with nodejs and I thought to create something like this Java input library, so I started with some rough code like below: ...
CodeYogi's user avatar
  • 5,087
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: ...
sakshamsaxena's user avatar
4 votes
1 answer
117 views

Invocation list implementation (signals/slots)

This class is mostly an educational exercise for me using some C++11 constructs. I wanted to create something similar to an "invocation list" in C#, i.e., a list of zero or more function objects which ...
TypeIA's user avatar
  • 151
1 vote
1 answer
2k views

TCP client library using Winsock WSAEventSelect in C++ - Take 2

This is my second take on creating a tcp client C++ class. The class declaration is general but the implementation is Windows only at this stage and uses the Microsoft Winsock WSAEventSelect model. ...
arcomber's user avatar
  • 2,449
2 votes
1 answer
1k views

TCP client library using Winsock WSAEventSelect in C++

One way to write a client which uses a specific protocol, eg http like in this case, is to create a base class with the basic socket handling functionality with virtual functions which can be ...
arcomber's user avatar
  • 2,449
2 votes
0 answers
601 views

Saving parsed CSV data to MongoDB

I wrote a script for reading a CSV, parsing it and saving data to MongoDB. I would love some input on how I'm handling errors and dealing with callbacks. I wrote it with nested without using async and ...
user137717's user avatar
2 votes
1 answer
203 views

Recursively walk directories with a callback function

This code works, but I want to refine it: ...
dopatraman's user avatar
1 vote
0 answers
1k views

TinyMCE plugin to save with cancel button

Please provide constructive criticism for this TinyMCE plugin which allows the user to save the content, or cancel and go back to the original. JS Bin ...
user1032531's user avatar