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
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:
...
3
votes
1
answer
2k
views
Node.js async callback hell
I'm attempting to create a final array with data pulled from 3 functions. The first two functions have all the data but then the 3rd function needs to run looping through one of the fields from ...
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 ...
1
vote
1
answer
7k
views
Node.js DynamoDB callback
I am writing an API which gets results from a DynamoDB table and puts the JSON back into the browser.
The code below works and returns the desired results. However, after reading about async and ...
2
votes
3
answers
31k
views
Time of day based timer - run function at certain time, daily
I need to call a function exactly at certain hour, daily, my programs runs 24/7.
I wrote the following timer mechanism, which generally works that way:
Calculate time until hour and generate timer ...
4
votes
1
answer
4k
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 ...
2
votes
1
answer
94
views
My yld NPM - callbacks/promises alternative
I'd like feedback on my callbacks/promises alternative, please.
The yld repository
...
3
votes
1
answer
3k
views
Javascript Queue for async functions
Based on the answer to my previous question on Stack Overflow, I put together the following Queue class. I realize there are already libraries out there to do this. However, I wanted to actually ...
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 ...
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. ...
1
vote
1
answer
215
views
Callback for job applicant
This is on a job listing site and it has a Linkedin apply button plugin - this provides for a callback the someone has applied for a job. I've written the callback function which extracts the Job ID (...
3
votes
2
answers
809
views
Passing Context in CoffeeScript
I'm trying to migrate from JavaScript to CoffeeScript. However I'm not sure about the best way to optimize the code generated by js2coffee.
Below is the original JavaScript source :
...
4
votes
1
answer
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 ...
1
vote
1
answer
9k
views
Calling a function when all asynchronous calls complete [closed]
Below is a simplified version of some code I am using to execute a function after all asynchronous calls complete. Is this a reasonable piece of code? It seems to work. Nothing would break if ...
1
vote
1
answer
543
views
Update subscription
First, some background. I have a Payment model that has_many :subscriptions. When a user pays (creates a new payment), I have an ...
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 ...
2
votes
2
answers
138
views
Allowing messages to be passed to listeners [closed]
I have written an implementation of the observer pattern that allows messages to be passed to listeners in what would normally be the notify() method. For example a ...
3
votes
1
answer
3k
views
Basic socket library in C
I am trying to learn C and have written a very basic socket library. I would be interested in any general design and coding comments.
Note that at this stage I am not bothered about implementing the ...
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:
...
3
votes
1
answer
269
views
Ruby Callback System
I need a way to store and retrieve callbacks in Ruby, so I made a Callbacks class. Any suggestions would be greatly appreciated.
...
3
votes
1
answer
5k
views
Efficient implemetation of AlertDialog callback in Android
One day I realised that my Android project utilizes AlertDialogs here and there in very ineffective way. The heavily duplicated portion of code looked like this (actually, copied and pasted from some ...
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:
...
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 ...
3
votes
1
answer
171
views
jQuery callbacks optimization
I have a lot of repeatable blocks of code and want to optimize/simplify them:
...
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 ...