chain

Javascript (typescript) Chrome extension, function callback as promises?

巧了我就是萌 提交于 2019-12-05 19:12:38
for a code like this let anotherFolder='whatever'; let anotherFolder2='whatever'; chrome.bookmarks.create( {title:'whatever2'}, function( parentFolder ) { chrome.bookmarks.move( anotherFolder, {parentId: parentFolder.id}, function() { chrome.bookmarks.removeTree( anotherFolder2, function() { resolve(); }); }); }); can I transform it to chain functions? Something like let anotherFolder='whatever'; let anotherFolder2='whatever'; return new Promise(function(resolve){ chrome.bookmarks.create( {title:'whatever2'}, function( parentFolder ) { resolve(parentFolder); }).then( (parentFolder) => { chrome

AngularJS promise chain

限于喜欢 提交于 2019-12-05 11:44:05
I have my application that should open a popup ask a confirmation at the user, then make an ajax cal and close the popup. I tried to do it using a chain of promise (I've already used it, and I remember that it should work in this way), but it seems to block after the call to reservationService.confirm($scope.object); . Now it is a fake service implemented with a setTimeout and $q just to return a promise (in future it will make the ajax call). Is this a valid code or I didn't undestood how promise works? For the popup I choose AngularUI and the code is this: reservationService.book($scope

Promise: Ignore Catch and Return to Chain

岁酱吖の 提交于 2019-12-05 00:40:00
Is it possible to ignore a catch and return back to the chain? promiseA() // <-- fails with 'missing' reason .then(promiseB) // <-- these are not going to run .then(promiseC) .catch(function(error, ignore){ if(error.type == 'missing'){ ignore() // <-- ignore the catch and run promiseB and promiseC } }) Is something like this possible? Here's the synchronous analogy: try { action1(); // throws action2(); // skipped action3(); // skipped } catch (e) { // can't resume } vs try { action1(); // throws } catch (e) { handleError(e); } action2(); // executes normally action3(); Here's the promise

get lhs object name when piping with dplyr

Deadly 提交于 2019-12-04 17:56:25
问题 I'd like to have a function that can use pipe operator as exported from dplyr. I am not using magrittr. df %>% my_function How can I get df name? If I try my_function <- function(tbl){print(deparse(substitute(tbl)))} it returns [1] "." while I'd like to have [1] "df" Any suggestion? Thank you in advance, Nicola 回答1: The SO answer that JBGruber links to in the comments mostly solves the problem. It works by moving upwards through execution environments until a certain variable is found, then

Javascript, spliced FileReader for large files with Promises, how?

匆匆过客 提交于 2019-12-04 06:15:27
问题 I'm trying to use FileReader to read several files sequentially using promises for that. The problem is that I need to divide the reading operations in several chunks to make them doable. By doing so, I lose the Promise chain. This is what happen in the following code, where I get the console log here , then catched (meaning I've lost the chain), then inside and then finished . Somehow the Promise in upload is not respected. Here it is the code (please go to the last EDIT, I keep the original

Chain a celery task's results into a distributed group

做~自己de王妃 提交于 2019-12-04 05:21:34
Like in this other question , I want to create a celery group from a list that's returned by a celery task. The idea is that the first task will return a list, and the second task will explode that list into concurrent tasks for every item in the list. The plan is to use this while downloading content. The first task gets links from a website, and the second task is a chain that downloads the page, processes it, and then uploads it to s3. Finally, once all the subpages are done, the website is marked as done in our DB. Something like: chain( get_links_from_website.si('https://www.google.com'),

Chain dynamic iterable of context managers to a single with statement

柔情痞子 提交于 2019-12-04 04:04:24
问题 I have a bunch of context managers that I want to chain. On the first glance, contextlib.nested looked like a fitting solution. However, this method is flagged as deprecated in the documentation which also states that the latest with statement allows this directly: Deprecated since version 2.7: The with-statement now supports this functionality directly (without the confusing error prone quirks). However I could not get Python 3.4.3 to use a dynamic iterable of context managers: class Foo():

Cypher: how to find all the chains of single nodes not repeated?

夙愿已清 提交于 2019-12-03 17:19:27
I want to find ALL the paths starting and ending from/to a specific node. I would like that each node in a path appears only once. For example, in a graph like this: (a)-[:REL]->(b)-[:REL]->(c)-[:REL]->(a) (a)-[:REL]->(e)-[:REL]->(f)-[:REL]->(a) (e)-[:REL]->(b) grafically: e → b ↙ ↖ ↗ ↘ f → a ← c Cypher code: CREATE (a { name:'A' })-[:REL]->(b {name:'B'})-[:REL]->(c { name:'C' }) -[:REL]->(a)-[:REL]->(e {name:'E'})-[:REL]->(f {name:'F'})-[:REL]->(a), (e)-[:REL]->(b) I would like that the research of chains starting from (a) returns (a)->(b)->(c)->(a) (a)->(e)->(f)->(a) (a)->(e)->(b)->(c)->(a)

attempting to break jQuery promise chain with .then, .fail and .reject

半城伤御伤魂 提交于 2019-12-03 02:28:19
Update: this issue was a result of jQuery 1.7 vs 1.8. Do not ever use promises in 1.7 beacuse they aren't chainable with returning a promise inside a .then . 1.8 looks like they didn't mess it up. http://jsfiddle.net/delvarworld/28TDM/ // make a promise var deferred = $.Deferred(); promise = deferred.promise(); // return a promise, that after 1 second, is rejected promise.then(function(){ var t = $.Deferred(); setTimeout(function() { console.log('rejecting...'); t.reject(); }, 1000); return t.promise(); }); // if that promise is successful, do this promise.then(function() { console.log('i

Javascript, spliced FileReader for large files with Promises, how?

半城伤御伤魂 提交于 2019-12-02 09:51:56
I'm trying to use FileReader to read several files sequentially using promises for that. The problem is that I need to divide the reading operations in several chunks to make them doable. By doing so, I lose the Promise chain. This is what happen in the following code, where I get the console log here , then catched (meaning I've lost the chain), then inside and then finished . Somehow the Promise in upload is not respected. Here it is the code (please go to the last EDIT, I keep the original text nonetheless) var reader = new FileReader(); reader.onloadend = function(e) { if (e.target