5

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?

drinking
  • 1,533
  • 3
  • 15
  • 22

1 Answers1

6

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)
Evan Drewry
  • 794
  • 6
  • 17