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
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: ...
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: ...
3
votes
1answer
55 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'...
2
votes
1answer
328 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 ...
7
votes
1answer
688 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 ...
3
votes
0answers
258 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 ...
4
votes
2answers
108 views

Initialising accounting groups

This deeply nested set of callbacks is very unreadable and I'm looking for ways to improve it: ...
5
votes
1answer
844 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 ...
1
vote
1answer
102 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 ...
1
vote
0answers
36 views

Cleanest way to write a callback that accepts a next sequence in javascript

I need to call multiple functions asynchronously before producing a result. In this case what are the possible improvements in the following code(also including other library like for promise etc.) ? ...
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 ...
1
vote
0answers
200 views

Chainable futures in Python

Here is a homemade Future class: ...
2
votes
1answer
499 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,...
1
vote
1answer
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: ...
10
votes
1answer
560 views

ActivityLifecycleHelper implementation

Description The ActivityLifecycleHelper uses wrap(Context)to create the class and save a global ...
-2
votes
1answer
2k 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 ...
3
votes
2answers
729 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 ...
1
vote
2answers
670 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 ...
0
votes
1answer
818 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 ...
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 ...
3
votes
1answer
373 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. ...
1
vote
0answers
44 views

AJAX Form Creator

I wrote an AJAX Form Creator (in the form of an js object constructor) that takes a form and a callback. I am a decent, slightly okay, completely novice developer, and could use feedback on coding ...
2
votes
1answer
109 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: ...
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
100 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 ...
1
vote
1answer
1k 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. ...
2
votes
1answer
739 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 ...
1
vote
0answers
553 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 ...
2
votes
1answer
164 views

Recursively walk directories with a callback function

This code works, but I want to refine it: ...
1
vote
0answers
840 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 ...
3
votes
1answer
38 views

JavaScript idle managing structure

I am just getting into the world of javascript, coming from the world of classical inheritance. The following is a library I wrote to track when a webapp is idling and I wrote it like I write ...
3
votes
0answers
1k views

C++ UDP server for a game

I broke my server into two classes, a general server class and a client session class. I know the code isn't documented in the header, but I am more interested in the design of the server/session ...
2
votes
1answer
30 views

Parallel computation to be merged, depending on single call

Steps: Get AMOUNT from a call to API endpoint /a, e.g. AMOUNT == 5 (in the code it is set ...
4
votes
1answer
2k views

PHP Route class

I was trying to keep it SRP. I'm new into PHP OOP and I'm wondering how I can make it better. Route.php ...
1
vote
0answers
166 views

Generic Timeout Handler

In a frontend Javascript project I have to implement a generic timeout mechanism for a set of asynchronous tasks that the program needs to perform. These are the conditions: The tasks are functions ...
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-...
4
votes
2answers
938 views

C++ EventHandler class, invoking & arguments

This is my EventHandler class, which is extremely simple and can be used on lambdas and similar: ...
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. ...
2
votes
1answer
138 views

Handling success and failure when retrieving product information

I've got an Angular controller where I have two functions that are repeated inside two functions: ...
0
votes
1answer
158 views

Operating on a list of files using recursion

I'm starting just now with CoffeeScript and I found out that I can't solve problems like looping and recursives with just one line. I would like to improve the code that I just wrote using built-in ...
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 ...
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 ...
1
vote
1answer
99 views

Taking and saving pictures using promises

I have the following 4 functions that work, however, I am sure that utilising promises will improve my code. I just find them so confusing. ...
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. ...
2
votes
1answer
2k views

Python lazy dictionary

Here is a lazy dictionary with test cases. ...
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 ...
2
votes
1answer
482 views

Handling callbacks when doing async programming and dealing with scope

I'm using HapiJS to create a little backend for my side-project. In grabbing RSS feeds, I want to loop through my list of website URLs, grab the correct RSS links in the ...
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 ...
4
votes
4answers
83 views

Indenting a function to recursively find filenames

I wrote this function that recursively traverses a given directory resolves the relative file-names to absolute file-names and yields the resolved file-name if it matches a given pattern. You can ...
2
votes
1answer
224 views

Conditional callback for asynchronous file copy

I'm trying to figure out the most elegant solution to do the following asynchronously using JavaScript (specifically node): Given a destination file name, check if it is a directory If it is a ...