callback

How do I convert an existing callback API to promises?

谁说我不能喝 提交于 2020-01-17 18:01:02
问题 I want to work with promises but I have a callback API in a format like: 1. DOM load or other one time event: window.onload; // set to callback ... window.onload = function() { }; 2. Plain callback: function request(onChangeHandler) { ... } request(function() { // change happened ... }); 3. Node style callback ("nodeback"): function getStuff(dat, callback) { ... } getStuff("dataParam", function(err, data) { ... }) 4. A whole library with node style callbacks: API; API.one(function(err, data)

How to pass content to controller from service after it is done being parsed?

我的未来我决定 提交于 2020-01-17 05:48:05
问题 I am trying to use the csvtojson node module to read content from a csv file so that I can display it in my html view. Below I follow the example provided on the csvtojson page. I am successfully reading and logging the contents of the csv file, but I cannot figure out how to pass the contents to my controller at the right time so that I can display them in my view. Currently, the code under // public api is returned before the csv is finished being parsed. Consequently, result is passed with

what is the callback in loopback (datasource.(automigrate))

≯℡__Kan透↙ 提交于 2020-01-17 05:29:11
问题 Loopback datasource API offers automigrate function with an optional callback. I see in some examples that the callback gets one parameter (err), but no definition of that. What form does the callback parameter have? Are there other possible parameters? How is this with the other functions? 回答1: Callbacks are nothing but the function which you passing as a parameter to the other function Look at this example function printResult(err,result) { if(err) { console.log('something went wrong');

Jquery deferred call back oddness

↘锁芯ラ 提交于 2020-01-17 02:53:15
问题 I was playing around with call backs and deferred functions in jQuery and was wondering if anyone could tell me why this works http://jsfiddle.net/austinbv/QVujr/ get_each_total = function(callback) { var requests; requests = []; var url; url = "http://otter.topsy.com/search.js?callback=?&apikey=38A260E9D12A4908B1AF9184B691131&q=justin+bieber&window=d"; return requests.push($.getJSON(url, function(data) { })); return $.when.apply($, requests).then(function() { callback(); }, function() {

Reading raw serial data in Matlab

北城余情 提交于 2020-01-17 02:21:26
问题 I'm trying to read some raw telemetry data via serial. Each message terminates with \r\n and there are 4 kinds of messages. I setup the port like this: if exist('s') fclose(s); delete(s); clear s; end s = serial('/dev/ttyS99'); s.BaudRate = 57600; s.BytesAvailableFcnMode = 'terminator'; s.Terminator = 'CR/LF'; s.DataBits = 8; s.Parity = 'none'; s.StopBits = 1; s.BytesAvailableFcn = @serial_callback; s.OutputEmptyFcn = @serial_callback; fopen(s); For the calback, i wrote a simple function

Calling BAPI_DOCUMENT_CHECKOUTVIEW2 using SAP.Net Connector 3.0 returns “RFC Callback server not available”

与世无争的帅哥 提交于 2020-01-17 01:31:04
问题 I am trying to get a document from SAP DMS using SAP.Net Connector 3.0. I need to get the document and display in ASP.Net. I am using "BAPI_DOCUMENT_CHECKOUTVIEW2" for calling the function. But when the invoke method is called, "RFC callback server not available" error is thrown. The code i have used is below. ... sap.RfcRepository repo = prd.Repository; sap.IRfcFunction testBapi = repo.CreateFunction("BAPI_DOCUMENT_CHECKOUTVIEW2"); testBapi.SetValue("DOCUMENTNUMBER", docNumber); testBapi

Pass received argument to a callback function

夙愿已清 提交于 2020-01-16 19:32:12
问题 I am working on a Gtk project in C. From the main.c I call a function1 with an int address as a parameter. In that function1 , I can access that first value, but then at the end (inside) of that function1 , I call another function2 (which is a callback function to a click event) and pass it the address I got from the function1 parameter. But in function2 , the address have changed, definitely can't figure out why ... My project looks like this : [main.c] int main(...) { int a = 50; function1(

PictureCallback not called when using takePicture in Android

大兔子大兔子 提交于 2020-01-16 18:48:34
问题 I'm taking a picture using my own camera and trying to save the result to the file system (/data/data/package.name/file/captured_photo1.jpeg). When i try it on the emulator (Android 2.2) it seems to work - creates a file with size 8733 bytes and displays it (emulator's default photo). The problem is that when i try it on my GalaxyS (Android 2.2.1) the image on the file system is 0 bytes i found out (from the log) that one of the callbacks i pass to my takePicture method isn't called. and it's

How to access index variable in a jquery getJson call ($.getJson) during a loop?

非 Y 不嫁゛ 提交于 2020-01-16 18:35:13
问题 I have the following code, which has been simplified for this question. Basically i have a loop, that, on each iteration, calls the jquery getJSON function, calling out to a API end point to grab some weather data. The problem is that i need to access the index from the loop, when the getJSON request was fired, and am having some troubles with it. I need to know what index the request was for, so i can match it with some data from a database. The code: function buildCities() { for (var i = 0;

How to pass a callback function pointer to epoll_event structure in C++

被刻印的时光 ゝ 提交于 2020-01-16 18:12:06
问题 I have been searching an answer for this question and I came across the functions timerfd_create and epoll in Linux. In a tutorial it was said that epoll_ctl() has an epoll_data_t union member of the epoll_event structure which can be used to execute a callback function on a timerfd event firing. But I am not sure on how to do it. Can anyone please help. 回答1: You can't put a callback function pointer into epoll_event because it can't fit in any of these slots: typedef union epoll_data { void