简体   繁体   中英

What's the main difference between ReactiveCocoa and PromiseKit?

ReactiveCocoa use RACSignal and PromiseKit use Promise to wrap values. They can both chain asynchronous works together. What's the main design difference between ReactiveCocoa and PromiseKit?

signals and promises are both ways to represent asynchronous operations as typed values that can be passed around, chained, composed, nested, etc in ways that a callback/notification/delegate cannot.

the difference between the two is like the difference between a square and a rectangle, where all promises are signals but not all signals are promises. a promise is one specific use case of a signal.

a signal represents a timeline of any number of asynchronous events, terminated by a completion or a failure. The following diagrams are all possible signals- any number of events ending in a failure or completion

--------------------Event(eventData)-Completion()

--------------Completion()

Event(eventData)---------Event(eventData)----------Failure(errorData)

-------------------------------------Failure(errorData)

a promise represents a single asynchronous event or a single asynchronous failure. the following diagrams represent possible promises:

-------Completion(eventData)

----------------------------------------------Completion(eventData)

--------Failure(errorData)

------------------------Failure(errorData)

as you can probably already see, any promise can be represented by a signal that sends Completion immediately after it sends its first Event, like so:

-------Event(data)+Completion()

-------------------------------------------Event(data)+Completion()

--------Failure(errorData)

------------------------Failure(errorData)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM