Swift gems for creating reliable, concurrent OS X desktop apps
pixelspark.nl
pixelspark.nl
I've used it in a few projects, and it makes dealing with async things feel surprisingly natural:
getLocation()
.then { apiRequest(params, location: $0) }
.then { json -> () in
for result in json["results"] {
display(result)
}
}
.catch { showError($0) }
It's also easy trivial to adapt existing callback-based[2] and delegate-based[3] APIs to promises.[1]: https://gist.github.com/Sidnicious/93d2a8db1266e2fd239c
[2]: https://gist.github.com/Sidnicious/69df2c483aadc08bda4f
[3]: https://gist.github.com/Sidnicious/99b099d9b6f2ecb9e383
Or, you could just make a logging serial queue that you send all log messages to; that way there's no risk of activity on the main thread slowing down your logging. In (Obj-)C:
static queue_t queue;
void log (NSString *message) {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
queue = dispatch_queue_create("logging", DISPATCH_QUEUE_SERIAL);
});
dispatch_async(queue, ^{
NSLog(message);
});
}http://www.istartedsomething.com/20091010/microsoft-free-roo...