Questions tagged [callback]

1

votes
1

answer
265

Views

Rails 5 - how to negate a method call on a before_save callback conditional

In my Template model I have this callback: before_save :set_status, if: :is_template? private def is_template? return self.template_type == 'template' end How can I change it so that it only fires when the template_type is NOT 'template'? I tried these: 1 before_save :set_status, if: !:is_template?...
rmcsharry
1

votes
2

answer
167

Views

Node callback style with promisify? “The 'original' argument must be of type function”

I'm using util.promisify in a Google Cloud Function to call IBM Watson Text-to-Speech, which returns a callback. My code works but I get an error message: TypeError [ERR_INVALID_ARG_TYPE]: The 'original' argument must be of type function The documentation says Takes a function following the common...
Thomas David Kehoe
0

votes
3

answer
22

Views

Is it possible to disable all others event when an event was executing?

For example i have some click event and while i trigger any selector's event, all other selector's event should be disable until current event finished executing. I clicked on selector-a then repeatly clicked on selector-b document.querySelector('.selector-a').addEventListener('click', function() {...
Mr. 8ty8
1

votes
2

answer
40

Views

PHP Using preg_replace_callback shortcodes function returns wrong elements order

I'm defining a function wich can handle shortcodes for users wisiwyg made posts. Using a function based on preg_replace_callback works great, but the returned replaced values prints before the initial string This is the handler function function shortcodify($string){ return preg_replace_callback('#\...
quakeglen
1

votes
2

answer
49

Views

How do I implement the map() function using a for loop?

I'm a beginner and I'm still trying to understand some concepts. I basically have to rewrite the behavior of the map() function using a for loop. Being an exercise from a course, part of the code has already been provided me: // the global Array var s = [23, 65, 98, 5]; Array.prototype.myMap = funct...
Blank
1

votes
1

answer
33

Views

How to pass different Generics in a Callback Class?

For a JFXTreeTableColumn I wrote a custom Cell Factory as Callback. Code works fine but what if I want to pass different Generics? I already tried to pass the Generics as ? or T, S but I definitely did something wrong public class CallbackImpl implements Callback { private final ObservableList payme...
thober35
1

votes
3

answer
118

Views

How to get callback from child component to parent component in React Native

I have been working on react-native to get the callback from child to parent. Below is the code snippet of my implementation: MainView.js import React, { Component } from 'react'; import { StyleSheet, View, Text, Image, TouchableHighlight, FlatList, Dimensions, } from 'react-native'; import ListCell...
vinay
1

votes
2

answer
39

Views

TS - class method is undefined in callback

I think that code is worth a thousand words. Take this example class Cat { constructor() { this.meow('roar', this.sound) } meow(a, callback) { callback(a) } sound(a) { console.log(a) console.log(this.sayMeow)
Raold
1

votes
2

answer
386

Views

different between callback and promise in node.js

my code : const readline = require('readline'); function scan(callback) { const rl = readline.createInterface({ input: process.stdin, output: process.stdout, prompt: '> ', }); rl.prompt(); rl.on('line', (line) => { callback(line); rl.close(); }).on('close', () => { process.exit(0); }); } scan(data...
Rife
1

votes
0

answer
121

Views

Passing callback to externally loading script in React

For some reason I don't want to use npm or Atmosphere Google Maps packages in my Meteor app. And try to use Google maps directly. So, inside a React Component I have the following render method and onMapLoaded() class method: render(){ return( (this.instance = el)}> Map ); } Can't figure out, how to...
Dmitry
1

votes
1

answer
578

Views

Node Js: how to execute functions async in the start of the server

I want to run a function from an exported file as the first function in the application (async way). this function must be executed the first when running the server and will ask us if it's a local or production environnement ! the function is in config file: //config/config.js: const readline = req...
Karim Garali
1

votes
1

answer
34

Views

Get values from list inside a node js callback [duplicate]

This question already has an answer here: Asynchronous Process inside a javascript for loop [duplicate] 6 answers I am using the node.bittrex.api without a problem. I am going through a loop of records and calling getticker for each record. The getticker call returns the values async which is fine,...
Koush
1

votes
1

answer
60

Views

I can't share data from request with JSON and Volley to other android activity

I am making a request with JsonObjectRequest and Volley in a java class and, once I get the data, I can't send it to the activity where I need to use it. I tried using a callback but I don't know what I am doing wrong. I've tried several things but none of them worked. I get the data correctly in my...
Probas Probas
1

votes
1

answer
47

Views

Different behaviour for setInterval if callback is blocked

I run much the same code in Firefox 58 and Chrome 63 on Linux count = 0 intv = 0 function f(){ let a console.log('start', performance.now()) for (let i=0;i
Austaras
1

votes
1

answer
293

Views

scipy basinhopping with callback: stop the algorithm when a condition is met

my objective is, while using a basinhopping algorithm in order to find a global minimum, to stop the alogorithm whenever a condition is met after a minimum is found. by looking at the docs here (https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.optimize.basinhopping.html), with speci...
Asher11
1

votes
0

answer
240

Views

Jupyter notebook button widget: Remove all click handlers?

It seems (correct me if I'm wrong), that when I invoke button.on_click(callback), the object button being an instance of ipywidgets.Button, the function callback is added to a list of click handlers. How can I access this list? I would actually like to clear this list. If I could find the callback l...
fmg
1

votes
1

answer
263

Views

How to implement interface to get callback in java [duplicate]

This question already has an answer here: What is a callback in java [duplicate] 6 answers I want to understand the concept of callback. I have searched on internet about the callbacks and there are many examples using interface, and one class is calling a method of another class using that interfa...
sheik
1

votes
1

answer
39

Views

How to load Images without callback hell?

I'm trying to load a couple of SVGs vie Fabric.js and push them into an array, to access them in the future. I have this small function that 'pushes' the pictures into the array. Everything works, BUT, because the asynchronous loading, I have not really a control where in the array the specific pict...
Michael Roebbeling
1

votes
2

answer
318

Views

NodeJS Mongodb distinct to array does not work

Hello try to use an mongodb distinct query with NodeJS (Async). In the GUI of Mongo this query works but in Node it returns the following error TypeError: db.collection(...).distinct(...).toArray is not a function The error returns on the following statement: mongo.connect(uri, function (err, db) {...
Erik hoeven
1

votes
1

answer
26

Views

PHP: access class method in callback function defined outside of class

I have a class like class Foo { public function runWithCallback($custom_callback) { ... return call_user_func_array($custom_callback, [$arg_a, $arg_b]); } public function aHelperMethod($arg_a) { ... } } And when I use the class like $foo = new Foo(); $foo->runWithCallback(function($arg_a, $arg_b) {...
Myles Fang
1

votes
1

answer
28

Views

Passing a callback to a function that is prefixed with await. Order of excecution

Let's say we have a mongoDB with cars, and users can add cars. The goal is to prevent more than one car with an identical license plate to be saved. Stack is node/express and mongoose. Scenario: A car with the provided license plate DOES already exist in the db. First attempt: console.log('Before ch...
Felix
1

votes
1

answer
257

Views

JavaScript Str.Replace with Promises

I need to do about 100 substring replacements in 1 large string variable. The rules are: I need that to be Sequential, so that the second replacement cannot be executed until the first is completed. Each subsequent replacement call must WAIT until the first is completed. The resulting string from th...
Luigino
1

votes
1

answer
241

Views

C - store different callback function adresses in an array

I'm trying to store different callback function addresses in an array. To be able to store function addresses with different signatures, I have defined a union and I use typecasting. This approach seems to work, but it is not very beautiful. Is there a better solution? typedef union { void (*callbac...
user1160713
1

votes
0

answer
37

Views

How do I configure Persona.ly Callbacks?

Could you comment an example of some callback code for Persona.ly? Their documentation is hard to understand! I'm not sure how to add callbacks natively for both these platforms (I don't want to use a server, I want to make Callbacks native on the device). //Code for Persona.ly @Override public void...
Ethan S.
1

votes
0

answer
79

Views

Can't access some object data post ajax

In the code below, why does console.log(myObject.obj1 ) display a proto object in the console instead of actual object data? Meanwhile, I can see the obj1 data using console.log(myObject). $(function () { var myObject = { obj1: {}, } $.ajax({ url: 'foobar.json', success: function (data) { myObject.o...
Stefan Dahl
1

votes
1

answer
41

Views

wait for json to be completed in javascript

I've read a very similar subject but i don't use JQuery. here's the problem : i want my json fully loaded before calling my function. I know that i must use a callback, but I dunno why my brain can't make it. here's the 'json' (truncated because it's not the subject): {type: 'robot', nom: '445250sup...
CoStiC
1

votes
1

answer
540

Views

Passing additional parameters to an Apps Script event object

I'm having a lot of headaches with callbacks and scopes in Apps Script. I have the following function, that creates a Gmail Add-On section with a checkbox for each attached file on the currently open email: function createAttachmentsSection( attachments ){ var widget = CardService.newSelectionInput(...
Manuel Herrera Ojea
1

votes
1

answer
43

Views

nodejs binding an object in callback function

Here is what I have tried. var obj = {sfsf: fsdfs}; connection.query('UPDATE table SET `qty` = `qty` - ? WHERE item_id = ?', [p1, p2], callback.bind(obj)) Callback function: function callback(f_err, f_rows, f_fields){ //default parameters err, rows, fields if(!f_err){ console.log(obj); //undefined /...
SO-user
1

votes
1

answer
47

Views

Nodejs function keeps executing even after “return callback()” is called

In the following function, it is my understanding that the code should stop executing after the callback if either of the first two if conditions is met, i.e. if either 'validate_post' returns an error or if '!clean.postId == true'. When I ran into the second if condition during testing, the callbac...
elemetrics
1

votes
1

answer
31

Views

Staying away from global state with sync callback handlers in AcornJS

I am using AcornJS and trying to stay away from global variables. I am looking for a functional paradigm that will allow me to accumulate an array of data from two handlers from the types.visit function, VID and VCE. I managed below to resolve them both to a single function, but what I really need i...
ThomasReggi
1

votes
0

answer
455

Views

Self-contained reproducible example of Python IB API with asyncio

The excellent ib_insync provides a higher level synchronous interface to the asynchronous IB API using the built-in asyncio module. However, there are situations where one might prefer to avoid relying on 3rd party modules. My attempt is to provide to the community a self-contained reproducible exam...
MLguy
1

votes
0

answer
132

Views

handlebar templates are not populating in sequence in a grid

The UI of the application is a 4x3 grid. Each tile in the grid gets poplulated by a external handlebar template. The seqence is like this - Create an JSON object of required data. data = {___:'',___:'',___:''...}; Push these objects into an Array called dataArray = [{},{},{},{}...]; Pass this arry...
ΛBHINΛV
1

votes
0

answer
557

Views

Kotlin Coroutine to escape callback hell

I'm trying to use Kotlin's coroutines to avoid callback hell, but it doesnt look like I can in this specific situation, I would like some thougths about it. I have this SyncService class which calls series of different methods to send data to the server like the following: SyncService calls Sync Stu...
julioribeiro
1

votes
1

answer
122

Views

LUA - Get Variable from Callback

I'm new at LUA coding and have the first problem: I try to make a http.get request and want to get the content to a variable. Here is my code: local API_KEY = '' function getAPIKey() local key http.get(SERVER_URL .. '?query=getapikey&mac=' .. wifi.ap.getmac(), function(code, data) if(code < 0) then...
hermanntoast
1

votes
1

answer
72

Views

Java anonymous class (implementing an interface) callback is null when passed to another function

I'm attempting to implement a callback for Android Java JsonObjectRequests. I've found dozens of posts showing code that is nearly verbatim. My problem is that the callback is null. See the two inline comments. public interface JsonObjectCallbackInterface { void onSuccess(JSONObject result); } class...
FirefighterBlu3
1

votes
1

answer
49

Views

Using javascript promises to return array upon a certain criterion

I am querying an API to get a list of songs. I then use each song to again, query the API to get its lyrics. The problem is that since the API calls are asynchronous the array of lyrics returns without getting a chance to be filled. I only want to return the array once all the lyrics have been inser...
dazzaondmic
1

votes
0

answer
704

Views

How to make a callback URL in PHP?

So I've been searching the net diligently and I can't seem to find a good(and basic) example of a callback. I get the idea of a callback but I can't make it work. Here's my sample code: $fp = fopen('file.txt','wb'); fwrite($fp,'sample content'); fclose($fp); Basically what it does is create a new t...
user3437905
1

votes
0

answer
93

Views

Trampolining a non-static C++ member as a registered C callback

I am writing a C++ freeGlut 3.0.0 application. I am having trouble registering a generic callback signature (hopefully a function pointer template argument) with a non static member function that matches the signatures of the declared free-glut callbacks. To this end, with the help from this answer...
johnco3
1

votes
0

answer
45

Views

ctypes callback works (more or less) while debugging but not independently

The pycanon package does not work with Canon's current ED SDK, therefore I have started from scratch making a new one. Progress comes step by step, but now I am stuck on catching the camera's events, which invoke a callback mechanism. There are at least two issues with it, and they may well be inter...
user508402
1

votes
0

answer
156

Views

Best practice for using callbacks with structs?

I want to use a callback on a struct which fails with the error 'Closure cannot implicitly capture a mutating self parameter' on the line self.pictures = catPictures How I understand it that has something to do with structs are value types and a closure holding a copy of it isn't really safe. The us...
Tysac

View additional questions