kseebaldt / deferred Goto Github PK
View Code? Open in Web Editor NEWAsync library inspired by CommonJS Promises/A spec
License: MIT License
Async library inspired by CommonJS Promises/A spec
License: MIT License
The platform of the target `Pods` (tvOS 9.0) is not compatible with `KSDeferred (0.3.0)`, which does not support `tvos`.
But it seems to be included in the podspec.
When attempting to chain to a promise via then:error: method, if the promise is cancelled nil is returned and the requester is potentially waiting on something that will never complete.
Maybe I'm missing something, but when I try to compile for iOS deployment target 6.1 using ARC I get these errors:
"ARC forbids explicit message send of 'release'"
"'release' is unavailable: not available in automatic reference count mode"
I'm seeing a bunch of these crashes at various places throughout our app:
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000000
Thread : Crashed: com.apple.main-thread
0 CoreFoundation 0x18301a698 -[__NSArrayM insertObject:atIndex:] + 504
1 my-app 0x10028f870 -[KSPromise then:error:] (KSPromise.m:124)
The offending line, KSPromise.m:124, reads [self.callbacks addObject:callbacks];
. Seems like self.callbacks
has disappeared by the time we call -[KSPromise then:error:]
. I suspect our misusage of the library might be at fault. Any idea of what usage pattern might cause something like this? Perhaps multiple attempts at resolution? We do have this plugged into an asynchronous API that is known to call its own callbacks more than once, so I could see how this could be the case.
Running KSDeferred 0.3.0 via CocoaPods.
Hi! I've been using KSDeferred for a while (thanks!), but I have to point Cocoapods to master
. Would it be possible to tag a new version?
Thank you so much for the effort put in this.
We use joins where we are collecting a list of objects being fetched. If any fetch fails, the aggregate operation is failed and our list ends up empty, but it would be better to get the list without objects that fail.
It would be good if a join could return the good and the bad. So, maybe something like:
typedef id(^joinPromiseCallback)(NSArray *values, NSArray *errors));
If you resolve a a KSDefer with nil and a related KSPromise is joined, then the app crashes. If the promise is not joined then it appears to work fine, but when joining promises either resolving or rejecting a defer with nil will result in an attempt to add nil to an NSMutableArray, which throws an exception.
from KSPromise.m:
For Example:
With KSPromises chained as follows:
promise3 --> promise2 --> promise1
If [promise2 cancel] is called, promise1 is also told to cancel, but promise 3 is never notified that the chain has been cancelled and is left in a state it cannot recover from on its own.
Currently it exits silently and early, but I have seen this give developers false confidence they are doing the right thing. Should this be changed to raise an exception (or perform a Debug-only assertion)?
Hi guys.... just inherited some code with this pod.
Is this pod still being maintained?
Can we have a tag for the latest code from 2019?
Why was a tag never created?
Thanks for all your support.
In a project I'm working on, a 401 (Unauthorized) status code is returned, along with some JSON message from the server for the reasoning (eg - too many failed login attempts, etc.).
So while an error is given, the NSData argument in the completion handler of -[sendAsynchronousRequest:queue:completionHandler:] is filled out, but using KSNetworkClient, there is no way to get this.
I know the code to fix this, but I can't seem to modify the NSURLProtocol correctly to make an example that would fail -- short of exercising with http://
The new method body of the KSNetworkClient would be like this:
- (KSPromise *)sendAsynchronousRequest:(NSURLRequest *)request queue:(NSOperationQueue *)queue {
KSDeferred *deferred = [KSDeferred defer];
[NSURLConnection sendAsynchronousRequest:request
queue:queue
completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
if (error) {
if (data) {
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:error.userInfo];
userInfo[KSResponseDataKey] = data;
error = [NSError errorWithDomain:error.domain
code:error.code
userInfo:userInfo];
}
[deferred rejectWithError:error];
} else {
[deferred resolveWithValue:[KSNetworkResponse networkResponseWithURLResponse:response
data:data]];
}
}];
return deferred.promise;
}
Which simply adds the NSData parameter to the userInfo key of the error if available.
I drove it out by hitting a service with basic auth (sadly).
fit(@"does a live http auth connection", ^{
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://demo.socialcast.com/api/authentication.json"]];
KSPromise *promise = [client sendAsynchronousRequest:request queue:queue];
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
[promise then:^id(id value) {
dispatch_semaphore_signal(sema);
return value;
} error:^id(NSError *error) {
dispatch_semaphore_signal(sema);
return error;
}];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
NSString *data = [[NSString alloc] initWithData:promise.error.userInfo[KSResponseDataKey] encoding:NSUTF8StringEncoding];
data should equal(@"true");
});
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.