Comments (6)
then
by default runs on the main thread. Would that work?
Generally I didn't expect dispatch_promise to be that often used.
from promisekit.
Like, really dispatch_promise
is not the usual way to start a promise. The documentation just happens to do it that way as the first example.
from promisekit.
Is the main way you expect promises to be created is through [Promise new:]? Which does run on the main thread.
from promisekit.
dispatch_promise
is just a convenience function that runs the provided block on a specific dispatch_queue
and returns a promise. The block executed by +new:
executes immediately in the queue new is called in.
from promisekit.
Usually you would wrap the +new:
in another method so the resulting usage reads better. Like this:
if (![self isOpponentDead])
return;
[self opponentFaint].then(^{
NSString *text = [NSString stringWithFormat:@"%@ fainted!", self.currentOpponent.name];
return [self showText:text];
}).then(^{
NSInteger expGain = [self.currentOpponent experienceGainedWhenDefeated];
NSDictionary *levelInfo = [self.currentPlayer gainExperience:expGain];
/// if you grew a level OR if you need to delete a move, do all that.
NSString *exp = [NSString stringWithFormat:@"%@ got %d exp points!", self.currentPlayerGuy.name, expGain];
return [self showText:exp];
}).then(^{
if (levelInfo == nil) {
[self opponentSendOutNext].then(^(NSNumber *didSendOut){
if (!didSendOut.boolValue) {
[self opponentLosingSequence];
} else {
[self emptyMoveQueue];
[self showMainMenu];
}
});
} else {
NSString *lvlUp = [NSString stringWithFormat:@"%@ grew to level %d!", self.currentPlayerGuy.name, self.currentPlayerGuy.level.integerValue];
[self updateLabels:NO];
[self showText:lvlUp].then(^{
//etc.
});
}
});
from promisekit.
Alright, that sounds good. I'll change how my promises start. Thank you!
from promisekit.
Related Issues (20)
- Cannot use URLSession.shared.dataTask(.promise, with: url) in my project HOT 1
- Problems building with Xcode 14.3 beta2 HOT 5
- dependabot requests HOT 1
- Update Cocoapod Release Version? HOT 9
- Website taken over by someone else? HOT 3
- Cocoapods's pods that depend on PromiseKit 6.22.1+ fail to `pod lib lint` while using Xcode 14.3 HOT 6
- Undefined symbols for architecture arm64 : PromiseKit HOT 3
- Xcode 15 Warning HOT 1
- promiseWithBooleanAdapterBlock HOT 8
- Add support of visionOS HOT 1
- SPM doesn't compile properly with version 8.x.x HOT 4
- Maige Usage
- Maige Usage
- Maige Usage
- Maige Usage
- Privacy Manifest HOT 16
- Request to updated SDK with the Privacy Manifest HOT 2
- Access authority HOT 3
- Release latest code to cocoapod HOT 8
- Why PromiseKit v7 was never released? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from promisekit.