기본 콘텐츠로 건너뛰기

라벨이 async인 게시물 표시

ReactiveX(Rx), Promise, 그리고 Future

Rx를 하다보니 fiber/future도 새롭게 보인다. 가령 비동기 구간을 setTimeout -> ..... , 1000 으로 하는 구현을 해보자. Rx.Observable.create (observable)->   # callback block   setTimeout ->     observable.onNext "<결과값>"   , 1000 .subscribe (res)->   console.log res 요건 Promise로 풀면 new Promise (resolve, reject)->   # callback block   setTimeout ->     resolve "<결과값>"   , 1000 .then (res)->   console.log res 거의 같은 모양을 하고 있다. 그 fiber/future로 풀면 doSomeAsync = ->   future = new Future()   setTimeout ->     future.return "<결과값>"   ,1000   future.wait() console.log doAsync() 핵심은 동기에서 return 에 들어갈 부분이 대체되고 그걸 외부에서 받는 부분이랑 한 쌍을 구성한다는 점인데 future는 c coroutine library 인 libcoro( https://github.com/ramonza/libcoro )를 사용하고 있다.  사실 coroutine만 해도 c에서 구현만 http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html  이렇게 다양한데. ECMA6 (coffeescript 1.10.0)...