BoltsFramework / Bolts-ObjC

Bolts is a collection of low-level libraries designed to make developing mobile apps easier.
Other
5.64k stars 576 forks source link

What is the things to watch out when using it? #274

Closed ruthless115 closed 8 years ago

ruthless115 commented 8 years ago

I'm wondering how often this BFTask operation will be used to be considered inappropriate . what's it limitation and things to watch out? Can other async implementation be forgotten and only use it? :neckbeard:

For example, what's the top number we can run under a responsive user touch event in theory? is there a way to measure it? If we don't need to worry about it at all and make every operation into 'Primise' like implementation. It looks awesome.

what's the difference between Bolts-ObjC vs Bolts-Swift, it even has Java and Android?

Why it has AppLink? it isn't in the short description of the Podfile.

Bolts was designed by Parse and Facebook for our own internal use, and we have decided to open source these libraries to make them available to others. Using these libraries does not require using any Parse services. Nor do they require having a Parse or Facebook developer account. The first component in Bolts is "tasks", which make organization of complex asynchronous code more manageable. A task is kind of like a JavaScript Promise, but available for iOS and Android.

Why would we want BFTaskCompletionSource? Considering we can use BFTask to do all those things?

For example

+ (BFTask *)taskWithBlock:(id (^)(BFTask *task))block;

And who created it? is it first comes from Parse? why there is no names in readme? I mean, other team did it. like vimeo, (not every project, only this)

ruthless115 commented 8 years ago

why we need to check if 1 != -1?


- (void)cancelAfterDelay:(int)millis {
    [self throwIfDisposed];
    if (millis < -1) {
        [NSException raise:NSInvalidArgumentException format:@"Delay must be >= -1"];
    }

    if (millis == 0) {
        [self cancel];
        return;
    }

    @synchronized(self.lock) {
        [self throwIfDisposed];
        [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(cancelPrivate) object:nil];
        if (self.cancellationRequested) {
            return;
        }

        if (millis != -1) {
            double delay = (double)millis / 1000;
            [self performSelector:@selector(cancelPrivate) withObject:nil afterDelay:delay];
        }
    }
}
ruthless115 commented 8 years ago

Is there a way we can debug better when using BFTask, hard to trace which block is executing

nlutsenko commented 8 years ago

what's it limitation and things to watch out?

The data consistency, as with any multi-threaded programming is still a concern, Bolts helps resolve that with say serial dispatch queues or serial operation queues, but I would recommend making sure your data stays consistent, as it's one of the biggest reasons for crashes in apps.

Can other async implementation be forgotten and only use it?

You can use Bolts Tasks and wrap any other async implementation with it, not sure how it makes it forgotten, but there is that.

For example, what's the top number we can run under a responsive user touch event in theory?

As many as you want, it all depends on how much work you are doing in every one of them.

is there a way to measure it?

Instruments.app to the rescue, specifically Time Profiler.

If we don't need to worry about it at all and make every operation into 'Primise' like implementation. It looks awesome.

Yup, you can do that, also I would recommend reading more on Executors here. It allows you run tasks on different threads/queues, not just the main thread.

what's the difference between Bolts-ObjC vs Bolts-Swift, it even has Java and Android?

Bolts-ObjC is the ObjC implementation of Bolts, Bolts-Swift - a Swift one. Even though you can use ObjC from Swift, if you have a Swift project and no dependencies on ObjC Bolts - I would recommend using that, taking into account that we have much more flexibility and type safety in Swift, that is not quite possible in ObjC.

Why it has AppLink? it isn't in the short description of the Podfile.

AppLinks for the current moment lives in Android and ObjC implementation of Bolts and partly it's due to legacy, partly due to the fact that it depends on Bolts/Tasks for the implementation.

Why would we want BFTaskCompletionSource? Considering we can use BFTask to do all those things?

TaskCompletionSource is the producer end of Tasks. If you are not using taskWithBlock:, but rather managing the concurrency and execution manually - TaskCompletionSource allows you to complete a task, and it's the only way to do so outside of an execution blocks on tasks.

And who created it? is it first comes from Parse? why there is no names in readme? I mean, other team did it. like vimeo, (not every project, only this)

Originally built by the Parse team at Facebook, being worked on by engineers at Facebook from the start.

why we need to check if 1 != -1?

Not sure which part you are referring to, but there is a possible optimization there, you are right (no need to check whether mills != -1 second time. Pull Requests are always welcome!

Is there a way we can debug better when using BFTask, hard to trace which block is executing

If you are using Xcode 7.3.1 or Xcode 8 - both of them can give you a trace in the debug navigator that jumps across multiple queues. To achieve more - we would need to inject stack frames or add debug information to any running block. If you have ideas on how to get that implementation going - Pull Requests are always very welcome.

nlutsenko commented 8 years ago

I hope the above answers all the questions you had. Feel free to reopen or comment on this issue if not.