기본 콘텐츠로 건너뛰기

라벨이 future인 게시물 표시

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)...

Fiber, future, 그리고 co-routine

맞춤법 검사를 위해 서버사이드에서 http.get 을 할 일이 있는데 meteor 에서 지원하는 future(node-fiber 라이브러리에 포함) 를 사용했다. 이거 블록으로 되어서 동시접속시에 망하는 거 아니냐라는 의혹을 불식시키기 위해 간단하게 코드를 짜보았다. meteor create future cd future vi future.js 하고 아래와 같이 부다다. if (Meteor.isClient) {   Template.hello.greeting = function () {     return "Welcome to future.";   };   Template.hello.events({     'click input' : function () {       // template data, if any, is available in 'this'       if (typeof console !== 'undefined')         console.log("You pressed the button");     }   }); } if (Meteor.isServer) {   Future = Npm.require('fibers/future');   Meteor.startup(function () {     // code to run on server at startup     Meteor.methods({       'future':function() {         console.log('future start:'+Date.now());         var fut...