promisekit

PromsieKit + Alamofire for loading paged HTTP Data

ぃ、小莉子 提交于 2021-01-28 19:06:51
问题 I am migrating some code from RestKit to Alamofire. I use MagicalRecord + AlamofireObjectMapper to map the JSON into CoreData objects. I am now faced with the following situation: My Data lives at this URL: http://domain.com/api/resources?start=XX&limit=YY Now I have to do this: Download the first page of data from a given URL using a page-size of 50 If the number of loaded objects is equal to the page-size increment the start parameter by the page size If the number is less than the page

How should I chain multiple Promises in PromiseKit 6

扶醉桌前 提交于 2021-01-07 06:26:55
问题 I am having a hard time using PromiseKit 6. I have several asynchronous functions which need to run one after the other so I need to chain them. I was wondering what's the correct way to use them. Also, no help from Here. So, as in PromiseKit6 , you have to return a Promise from then , which is what is specifically giving me headache. I have an example: First Function func A()->Promise<[String]> { return Promise { seal in //Do some Asynch operation and got String Array , `temp_Array` seal

讲讲 Promise

醉酒当歌 提交于 2020-07-27 15:16:30
一、什么是 Promise 1.1 Promise 的前世今生 Promise 最早出现在 1988 年,由 Barbara Liskov 、 Liuba Shrira 首创(论文: Promises: Linguistic Support for Efficient Asynchronous Procedure Calls in Distributed Systems )。并且在语言 MultiLisp 和 Concurrent Prolog 中已经有了类似的实现。 JavaScript 中, Promise 的流行是得益于 jQuery 的方法 jQuery.Deferred() ,其他也有一些更精简独立的 Promise 库,例如: Q 、 When 、 Bluebird 。 # Q / 2010 import Q from 'q' function wantOdd () { const defer = Q.defer() const num = Math.floor(Math.random() * 10) if (num % 2) { defer.resolve(num) } else { defer.reject(num) } return defer.promise } wantOdd() .then(num => { log(`Success: ${num} is

讲讲 Promise

╄→гoц情女王★ 提交于 2020-07-27 11:50:12
一、什么是 Promise 1.1 Promise 的前世今生 Promise 最早出现在 1988 年,由 Barbara Liskov 、 Liuba Shrira 首创(论文: Promises: Linguistic Support for Efficient Asynchronous Procedure Calls in Distributed Systems )。并且在语言 MultiLisp 和 Concurrent Prolog 中已经有了类似的实现。 JavaScript 中, Promise 的流行是得益于 jQuery 的方法 jQuery.Deferred() ,其他也有一些更精简独立的 Promise 库,例如: Q 、 When 、 Bluebird 。 # Q / 2010 import Q from 'q' function wantOdd () { const defer = Q.defer() const num = Math.floor(Math.random() * 10) if (num % 2) { defer.resolve(num) } else { defer.reject(num) } return defer.promise } wantOdd() .then(num => { log(`Success: ${num} is

Correctly chain multiple promises in PromiseKit 6

落爺英雄遲暮 提交于 2020-07-21 10:20:51
问题 I'm using Promisekit 6 and have 3 functions defined, all of which return promises. the first fetches data from a local database and the second from an online API server. the third, Foo, checks if the data with a given id exists locally, otherwise it checks online and returns it. I'm having trouble figuring out how to correctly chain the promises. Below is what I came up with thus far, but I'm not certain if creating a new promise is a good idea. Any feedback is appreciated. Thanks :) func

Swift PromiseKit: Equivalent to when() which executes sequentially?

痴心易碎 提交于 2020-04-13 09:13:32
问题 I'm using PromiseKit with Swift, which has been very handy so far. One of the functions they provide is when() , which allows you to have an array of any number of promises and execute something only once ALL of them have completed. However, the promises in the array are executed in parallel. I have not found any function that allows me to execute them sequentially. I've tried to write a recursive function of my own, but it doesn't appear to be executing the promises in the order in which

Swift PromiseKit: Equivalent to when() which executes sequentially?

帅比萌擦擦* 提交于 2020-04-13 09:12:20
问题 I'm using PromiseKit with Swift, which has been very handy so far. One of the functions they provide is when() , which allows you to have an array of any number of promises and execute something only once ALL of them have completed. However, the promises in the array are executed in parallel. I have not found any function that allows me to execute them sequentially. I've tried to write a recursive function of my own, but it doesn't appear to be executing the promises in the order in which

Swift PromiseKit: Equivalent to when() which executes sequentially?

可紊 提交于 2020-04-13 09:10:19
问题 I'm using PromiseKit with Swift, which has been very handy so far. One of the functions they provide is when() , which allows you to have an array of any number of promises and execute something only once ALL of them have completed. However, the promises in the array are executed in parallel. I have not found any function that allows me to execute them sequentially. I've tried to write a recursive function of my own, but it doesn't appear to be executing the promises in the order in which

Swift & PromiseKit: Resolving ALL promises from a loop

泪湿孤枕 提交于 2020-01-13 09:44:10
问题 I'm looking for a solution in Swift3 to resolve a dynamic number of promises all at once, e.g. like this sample in JavaScript: var promises = []; for(var i = 0; i < 5; i++) { var promise = $http.get('/data' + i); promises.push(promise); } $q.all(promises).then(doSomethingAfterAllRequests); https://daveceddia.com/waiting-for-promises-in-a-loop/ There was a library call 'Craft' for Swift2 that could do that (https://github.com/supertommy/craft), but it's no longer maintained. Does anyone know