My first nio project


(Gábor Sebestyén) #1

Hi folks,

To have a grasp on Swift NIO I decided to port my toy project OSCCore on top of it and see if it can work out. Today I reached the completed status so both the core module and the examples now powered by Swift NIO.

What I learned so far

  • The learning curve was a bit steep to me. Dealing with futures and promises (why do they both exist?) is still challenging.
  • However building blocks are easy to understand. To extend the pipeline with a byte pack to OSC message converter was a piece of cake.
  • The whole project looks very Java-ish. It's ok to me, but I hope it will be transformed to more Swift friendly in the future.

My work can be found here: https://github.com/segabor/OSCCore/tree/nio
I appreciate your suggestions and tips.
Thanks,

Gábor


(Helge Heß) #2

Those are just two sides of the same thing (the consuming side being the Future and the producing side the Promise). Kinda like addObserver and postNotification in NotificationCenter. Makes sense?


(Gábor Sebestyén) #3

I got it. But still wondering why both types are used. In Java (or even JS) world they fulfill the same purpose.

I come from Java world. Last time I used Foundation framework it was part of OpenStep API :slight_smile:


(Cory Benfield) #4

The reason for both types is to express intent. A Future can only be waited for, not fulfilled. Conversely, a promise can be fulfilled but not waited for (though you can extract a future from a promise). The type indicates what you should do with the object, which helps you communicate intent.


(Gábor Sebestyén) #5

I think I got the point now. Popular implementations deals only with one side of the coin.
Thanks for the clarification,

Gábor