cavinkwon / futre_channel_in_rb Goto Github PK
View Code? Open in Web Editor NEWconcurrent-ruby gem을 활용한 비동기 작업 알아보기
License: MIT License
concurrent-ruby gem을 활용한 비동기 작업 알아보기
License: MIT License
일단 안정버전의
concurrent-ruby을 사용하여
api = ->param{ param == 4 ? raise : param }
jobs = 4.times.map{ |i| Concurrent::Promise.execute{ api.call(i) } }
Concurrent::Promise.zip(*jobs).value #=> [0, 1, 2, 3]
jobs = 5.times.map{ |i| Concurrent::Promise.execute{ api.call(i) } }
Concurrent::Promise.zip(*jobs).value #=> nil
위와 같은 결과를 얻을 수 있는데요,
Concurrent::Promise#zip의 [문서]에
Builds a promise that produces the result of promises in an Array and fails if any of them fails.
위와 같이 나와있는것을 확인하였습니다.
zip을 호출하면서 넘긴 *promises
에 어떤것이라도 실패하면 zip의 리턴이 nil
이 되는것 자체는 정상동작인것은 알겠는데,
제가 원하는건 exception이 발생하였더라도,
Concurrent::Promise.zip(*jobs).value #=> [0, 1, 2, 3, RuntimeError]
이런식으로라도.. 성공한 Promise의 value는 받고싶은데... 방법이 없을까요..?
써주신 문서의 에러 핸들링부분을 보면 concurrent-edge의 Concurrent.future
와 Concurrent.zip
을 통해서 제가 원하는 결과가 보이긴 하는데
제가 원하는대로 하려면 concurrent-edge를 꼭 사용해야하나요? 안정버전에서는 방법이 없을까요?
좋은글 감사합니다.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.