Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 734
drinking Avatar asked Jan 18 '16 03:01

drinking


1 Answers

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)
like image 69
Evan Drewry Avatar answered Nov 10 '22 07:11

Evan Drewry