GithubHelp home page GithubHelp logo

Comments (6)

mxcl avatar mxcl commented on September 18, 2024

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.

mxcl avatar mxcl commented on September 18, 2024

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.

ethanmick avatar ethanmick commented on September 18, 2024

Is the main way you expect promises to be created is through [Promise new:]? Which does run on the main thread.

from promisekit.

mxcl avatar mxcl commented on September 18, 2024

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.

mxcl avatar mxcl commented on September 18, 2024

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.

ethanmick avatar ethanmick commented on September 18, 2024

Alright, that sounds good. I'll change how my promises start. Thank you!

from promisekit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.