Future<?>
Vertx.io API 도큐먼트 는 Future<?>를 다음과 같이 소개합니다.
더보기
Represents the result of an action that may, or may not, have occurred yet.
아직 발생하지 않은, 또는 발생하지 않을 결과를 나타냅니다.
Future<?>를 사용하면 여러 개의 비동기 결과를 한 번에 처리 할 수 있습니다.
병렬 구성(Concurrent composition)
직렬 구성(Sequential composition)
여러 비동기 작업을 병렬로 수행
여러 비동기 작업을 직렬로 수행
병렬 구성: CompositeFuture.all
CompositeFuture.all 를 사용하여 여러 개의 Future<?> 인자를 병렬로 처리 할 수 있습니다.
아래 예시 코드는 두 개의 Future<?> 인자의 동시 처리 방법을 보여줍니다.
Future<Void> future0 = Future.future(prom -> someHandler0(prom));
Future<Void> future1 = Future.future(prom -> someHandler1(prom));
CompositeFuture.all(future0, future1).setHandler(asyncResult -> {
// 모든 핸들러가 성공한 경우
if (asyncResult.succeeded()) { }
// 핸들러가 하나라도 실패한 경우
else { }
});
병렬로 처리 할 수 있는 Future<?> 인자는 최대 6개까지 오버로딩(Function overloading) 됩니다.
6개보다 더 많은 인자를 사용하려면 리스트를 사용합니다.
// 최대 6개의 Future<T> 인자를 사용
static <T1, T2, T3, T4, T5, T6> CompositeFuture all(Future<T1>, Future<T2>, Future<T3>, Future<T4>, Future<T5>, Future<T6>);
// List<Future>를 사용하여 인자의 개수에 자유롭게 사용
static CompositeFuture all(List<Future>);
인자로 전달된 모든 Future<T>는 병렬로 실행되며, 각 비동기 결과로 모두 성공 또는 하나라도 실패 한 경우에 결과를 반환합니다.
따라서 성공 케이스에 대한 실행 속도는 마지막 Future<?>의 응답 시간에 달려있습니다.
https://viewer.diagrams.net/?tags=%7B%7D&highlight=0000ff&edit=_blank&layers=1&nav=1&title=%E1%84%86%E1%85%AE%E1%84%8C%E1%85%A6.drawio#R7Ztdj5s4FIZ%2FTaTdi1TGfF92vrZatavtjtR2rlYe8ARXDo7ANEl%2FfQ2YEONAUyVMgOZmJj62D3B8ntc6JpmZt8vNXwlaRR9YiOkMgnAzM%2B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YfTHPUNnF4uTgu4lrfJNXDAh%2F55gHNfjTe9zpk4b7bTwMQ7F29NR33zptdVO94AisP8b%2BElENUWxVys0DQ4tA%2Bnj1yGuXFamrwCc%2Fpbwi7m5PFMK3DKSY16iDN0Ft2f1GSjKe70urw4GADLqex9Ld9EqPc%2B22288zmVw8q1YR902z%2Bmu6OdK6dNTsdaExpAr%2BcNe0qgyqT93UjVa%2F0rqaMuJg2gHwTAiZEKf0dS9UOCK6mjLkMNoB8hWBMjteWbK%2BMkVTTrX7yUw%2BsfDpn3PwA%3D
Future[0]
Future[1]
Future[2]
Future[3]
CompositeFuture.all()
Success (250ms elapsed)
Success (100ms elapsed)
Success (450ms elapsed)
Success (150ms elapsed)
Success (450ms elapsed)
실패 케이스의 실행 속도는 첫 번째 실패 응답이 발생하기까지 걸리는 시간에 달려있습니다.
https://viewer.diagrams.net/?tags=%7B%7D&highlight=0000ff&edit=_blank&layers=1&nav=1&title=%E1%84%86%E1%85%AE%E1%84%8C%E1%85%A6.drawio#R7Vtdk9smFP01nmkfnEHo%2BzH71U4mySTdmbb71GEl1qKDhQeh2M6vD7KQZYSlOrW1lrx%2BsrjABR3uOfiCPbFv56vfOFokn1iM6QSCeDWx7yYQQuA78qOwrEuLBTxYWmacxMpWGx7Jd1w1VNacxDjTGgrGqCAL3RixNMWR0GyIc7bUm70wqo%2B6QDNsGB4jRE3rXyQWSWkNoF%2Fbf8dkllQjW15Y1sxR1Vi9SZagmC13TPb9xL7ljInyab66xbRAr8Kl7PfQUrudGMepOKSD%2FZl8irMkeP4nz8Ppn3%2Bsvz59mPqumpxYV2%2BMYwmAKjIuEjZjKaL3tfWGszyNceEWyFLd5iNjC2m0pPFfLMRarSbKBZOmRMypqsUrIv4uur9zVelpp%2BZupTxvCuuqkAq%2B3ulUFJ926%2Bpum1LdL35fxIEspizFpeWBUKrqY5Qlm3cphi%2FBKBBoBVmZMpbzCHcha2%2FXWLIDszmWs5IdOaZIkG%2F6AEhF6Wzbbtv1CyNyaAgqSgWKUYpQvg10FwLxGRaqVx0O8mFnGrVpEyQ%2FEzB2Odw3RHP1Dg%2B5yDmeuDdg4t4Z4aQHyzIhAj8u0Aa6pdQMPTCUb8wFXnWvgAlsBZCtA%2BQ4CqBlTV8LKFuyQ10HtK%2BFhuJPQ%2BaMDLJtTJ0PMu8qSz3Jktq4SpnoahgcqV%2FHBYDfzhlrCJyx%2FcHJTDAyyAYgM%2BFVZvqRmQAcKDNBS8y8jsxU09zHGTgEzrjW0GQmsEYG2fllJoBXmelJZuxDZcY5q8x0JE32EDjjuYOTmY6kaZCQDUBm%2FPHIzJnkwj1ULryzyoVrxP4tmy9YJmNakQB6VM7%2F5pnLp1nxhCj95dezkyIcnIx4FwLlAOQlNKA09aYmdkRRlpFIx0UH8VBmmxjtgODuwaCyHXnW6kB9DVzYwLYUHOOs1XBkOf%2FhqOdD29BMcx7zKMJZtnfH%2BIieMdUXDlEyS4tVlSuDuTQUsU0iRN%2BrijmJ43JDwRn5jp43%2FopFXhQvtXlN96bYtzvIoe5wVOfJ9uZkNyA6QrOVSlPwDsJKCY6MiakN9S7s5SXD%2FayamWldOOF80OCJ456IcE1HfRMOGkv3gAiVC3ERfAu7ty7JN8sC%2Fon41ujSI9%2FMLO1Ivv2v77HnIl%2FzZtEDJ9rtDEd9k89MHT%2BzYn5EfvHjAqlRx8%2FClhvmmoUghOFpWOi%2FGgnN3OctkdD1GtwJTkXCpqO%2BSWgmXpdJQnd%2FuCjYp9ZxYfEKhDOvDbsIp85rDmObfqozdO41rifHm%2B2ZifrmpADMLyTdC1t%2BmlBvfK7fuAQ6loeVa8vd67Z%2Fmm7Peq48bfJ0rEmiBcwE33IviagqaN8aU83k%2F8rUUWeUFjCPBuCFMRW%2BRaaaJwVXpo467bSAeX7gXBhTW37KMk6mymL9F5iyef1PIvv%2BBw%3D%3D
Future[0]
Future[1]
Future[2]
Future[3]
CompositeFuture.all()
Not important (250ms elapsed)
Success (100ms elapsed)
Not important (450ms elapsed)
Failed (150ms elapsed)
Failed (150ms elapsed)
병렬 구성: CompositeFuture.any
CompositeFuture.any 역시 여러 개의 Future<?> 인자를 병렬로 처리합니다.
CompositeFuture.all 과의 차이점은 각 비동기 결과 중 하나라도 성공 또는 모두 실패 한 경우에 결과를 반환하는 점입니다.
Future<Void> future0 = Future.future(prom -> someHandler0(prom));
Future<Void> future1 = Future.future(prom -> someHandler1(prom));
CompositeFuture.any(future0, future1).setHandler(asyncResult -> {
// 핸들러가 하나라도 성공한 경우
if (asyncResult.succeeded()) { }
// 모든 핸들러가 실패한 경우
else { }
});
마찬가지로 6개보다 더 많은 Future<?> 인자를 사용하려면 리스트를 사용합니다.
// 최대 6개의 Future<T> 인자를 사용
static <T1, T2, T3, T4, T5, T6> CompositeFuture any(Future<T1>, Future<T2>, Future<T3>, Future<T4>, Future<T5>, Future<T6>);
// List<Future>를 사용하여 인자의 개수에 자유롭게 사용
static CompositeFuture any(List<Future>);
인자로 전달된 모든 Future<T>는 병렬로 실행되며, 각 비동기 결과로 모두 실패 또는 하나라도 성공 한 경우에 결과를 반환합니다.
따라서 성공 케이스에 대한 실행 속도는 첫 번째로 성공하는 Future<?>의 응답 시간에 달려있습니다.
https://viewer.diagrams.net/?tags=%7B%7D&highlight=0000ff&edit=_blank&layers=1&nav=1&title=%E1%84%86%E1%85%AE%E1%84%8C%E1%85%A6.drawio#R7Vtdj5s4FP01kbYPGRmDAzx2vnZVTau2I7U7TysPeIJXDo6MaZL%2B%2BppgQsCBTTdhApk8BV%2Fsa%2Fv4nuNcOxnZN7PlnwLPo488JGwEQbgc2bcjCCFwHfWRWVa5xQLIzy1TQUNtKw2P9CcpKmprSkOSVCpKzpmk86ox4HFMAlmxYSH4olrthbNqr3M8JYbhMcDMtH6noYxyqwfd0v4XodOo6Nma6PnNcFFZzySJcMgXWyb7bmTfCM5l%2FjRb3hCWoVfgkre7b3i7GZggsdyngf2JfgyTyHv%2BJ0398bevqy9PH8Yu0oOTq2LGJFQA6CIXMuJTHmN2V1qvB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aN8aU83s%2F8LUQWeUFjCPBuCZMRW%2BRaaaJwUXpg467bSAeX7gnBlTG37LMkymqmL5H5i8evlXIvvuFw%3D%3D
Future[0]
Future[1]
Future[2]
Future[3]
CompositeFuture.any()
Not important (250ms elapsed)
Failed (100ms elapsed)
Not important (450ms elapsed)
Success (150ms elapsed)
Success (150ms elapsed)
실패 케이스의 실행 속도는 마지막 Future<?>의 응답 시간에 달려있습니다.
https://viewer.diagrams.net/?tags=%7B%7D&highlight=0000ff&edit=_blank&layers=1&nav=1&title=%E1%84%86%E1%85%AE%E1%84%8C%E1%85%A6.drawio#R7Ztdj5s4FIZ%2FTaTdi1TG4ACXna%2BtVu1quyO1nauVJ3iCKwdHYJqkv74GTIhxoKkSJkBzMxMf7AM%2BPs9rHZNM7Nvl5q8Yr8IPPCBsAkGwmdh3EwghcB35L7NsC4sFkF9YFjENlK0yPNLvpOyorCkNSKJ1FJwzQVe6cc6jiMyFZsNxzNd6txfO9Luu8IIYhsc5Zqb1Mw1EWFg96Fb2d4QuwvLO1kzNb4nLzmomSYgDvt4z2fcT%2BzbmXBSflptbwrLolXEpxj00XN09WEwiccwA%2Bx%2F6IUhC7%2Fn%2FNPWnn%2F7bfnz6e%2Boi9XBiW86YBDIAqsljEfIFjzC7r6w3MU%2BjgGRugWxVfd5zvpJGSxq%2FEiG2ajVxKrg0hWLJ1FWyoeJLNvwNUq2nvSt3G%2BU5b2zLRiTi7d6grPm0f60alreqccHbLA9kM%2BIRKSwPlDF1PcBJmM8lu30RjCwCjUFWpoSn8Zy0RdberbGkg%2FAlkU8lB8aEYUG%2F6TfAKksXu367of9yKm8NQYmUp4hSQLk20F0IHC%2BIUKOqdJAf9h6jMuVJ8isJYxe3%2B4ZZqubwkIo0JhN0AybozkgnPVnWIRXkcYXz0K2lZuiJoXyTWJBN%2BwqYgS0DZOsBchwVoHWFrwWULdxD1wHNa6FF8ZdD5gwsZLuculzIZldZ6kiW1MZVyERbR%2B9E%2FTotAdxmZqw%2BMGO7vZMZb2Ah64HM%2BFeZ6UZmPHCkzHgNOfM6MlM%2B5iFmYB%2BYQVbfZMazBhayy8uMB68y05HM2MfKjHNRmWkpmuw%2BMDNDvZOZlqKplyHrgcy4w5GZC8kFOlYuZheVC2Tk%2Fi1frngic1pBAGdMPv%2FNcyw%2FLbJPONr%2B8efFofB7JyOzkYSyB%2FLim4psCk5F9pzhJKFzPTB6FI9F2wzSXhTQgSCUthMPWx2oLwKCteAWimMcthqOLOcnjjo%2BtfUP1DmYMrkQh3aM9%2FiZMH3dMKOLKFtUuTAkloYst%2Bkcs7fqwpIGQbGhkIR%2Bx8%2B5v2yNV9mc8lmim2zfboFDvcNRgye7Nyf7%2BdCSmo0oTcEbCEslODElpjbUh%2FCXl4R0s2hmpTVy3lxQw8RBZ%2BKt7qhr3uCoefPbty7Jm2UB90y81YZ0yJtZpY2ct%2FrLxBk40%2F5mOOqatwPV4ph4a3iXXPEGfOifhzf31XAzq5yR44ZmNUq8c%2BFWd9Q1bmZVVeIGcJT%2FzZ3MZanFiBgNhuhw9qhVmFqnZckrIGe%2BImxDTp3NNPKmHdPoJzh9R9H9ST02mMLOLMrzUwGwTEbCXMPXEKqtD7m1Fz6ncli6ttBBt91jujvXuXJa53SoBaEFzGLeQmMCVSXt70aqWehfSR10KWkB8xgAjoxU%2BDuSah4RXEkddBVqAfMEwRkZqQ1fWxkmqbJZ%2Fdyl6F79asi%2B%2FwE%3D
Future[0]
Future[1]
Future[2]
Future[3]
CompositeFuture.any()
Failed (250ms elapsed)
Failed (100ms elapsed)
Failed (450ms elapsed)
Failed (150ms elapsed)
Failed (450ms elapsed)
병렬 구성: CompositeFuture.join
Future<?>를 병렬 구성 할 수 있는 마지막 방법은 CompositeFuture.join 입니다.
join은 항상 모든 핸들러가 리턴되었을 때 콜백됩니다.
Future<Void> future0 = Future.future(prom -> someHandler0(prom));
Future<Void> future1 = Future.future(prom -> someHandler1(prom));
CompositeFuture.join(future0, future1).setHandler(asyncResult -> {
// 핸들러가 모두 리턴되었으며 모두 성공한 경우
if (asyncResult.succeeded()) { }
// 핸들러가 모두 리턴되었으며 실패한 핸들러가 하나라도 있는 경우
else { }
});
마찬가지로 6개보다 더 많은 Future 인자를 사용하려면 리스트를 사용합니다.
// 최대 6개의 Future<T> 인자를 사용
static <T1, T2, T3, T4, T5, T6> CompositeFuture join(Future<T1>, Future<T2>, Future<T3>, Future<T4>, Future<T5>, Future<T6>);
// List<Future>를 사용하여 인자의 개수에 자유롭게 사용
static CompositeFuture join(List<Future>);
인자로 전달된 모든 Future는 병렬로 실행되며, 각 비동기 결과로 모두 성공 또는 하나라도 실패 한 경우에 결과를 반환합니다. CompositeFuture.all 과의 차이점은 결과 반환 시점이 항상 모든 핸들러가 리턴했을 때라는 점입니다.
따라서 성공 및 실패 케이스에 관계 없이 실행 속도는 마지막 Future의 응답 시간에 달려있습니다.
https://viewer.diagrams.net/?tags=%7B%7D&highlight=0000ff&edit=_blank&layers=1&nav=1&title=%E1%84%86%E1%85%AE%E1%84%8C%E1%85%A6.drawio#R7Vtdk5MwFP01ndGHOiFAgUf3S8dRR90ZdZ%2BcLGRLnJR0INjWX2%2BAUBpSsE7LFrAvu%2BSS3JBz7znpDe3EvF6s38RoGX5gAaYTCIL1xLyZQAiBY4l%2FmWVTWAxge4VlHpNA2irDPfmNy47SmpIAJ0pHzhjlZKkafRZF2OeKDcUxW6ndnhhVZ12iOdYM9z6iuvUbCXhYWF3oVPa3mMzDcmZjJte3QGVnuZIkRAFb7ZjM24l5HTPGi6vF%2BhrTDL0Sl2LcXcPd7YPFOOKHDDA%2Fkg9BErqPP9LUm379svn88G7q2PLh%2BKZcMQ4EALLJYh6yOYsQva2sVzFLowBnboFoVX3eM7YURkMYf2LONzKaKOVMmEK%2BoPIuXhP%2BPRv%2Bypath507N2vpOW9sykbE483OoKz5sHuvGpa3qnHB6ywPRDNiES4sd4RSeT9ASZivJZu%2BACNDoBFkaUpYGvu4DVlzG2PBDswWWDyVGBhjijj5pU6AZJbOt%2F22Qz8xIqaGoKSUKxklCeWYQHXBUTzHXI6q0kFc7DxGZcqT5F8Sxiym%2B4VoKtdwl%2FI0xhP7CkzsGy2d1GRZhYTj%2ByXKoVsJzVATQ%2FrGMcfr9gjowJYAmSpAliUBWlX0NYC0hTvUtUBzLBQU%2Fxkya2CQbXPqfJDNLrLUkSzJjauQibaO7pH6dVwCOM2cMfrAGdPpncy4A4OsBzLjXWSmG5lxwYEy4zbkzPPITPmY%2BzgD%2B8AZ2%2BibzLjGwCA7v8y48CIzHcmMeajMWGeVmZaiyewDZ2Z272SmpWjqJWQ9kBlnODJzJrmwD5WL2VnlwtZy%2F5otliwROS1JAGdUPP%2FVYyyu5tnVT0aiFy%2FPzgqvdzoyGwuWPRAYT9dkXXIqbvsUJQnxVWBUFA8ltw7SDgr2HhBK25HHrRZUg2DDGriF5mjHrZojw%2FqLo47Pbb09lQ4iVARi357xHj1iqsYNUTKPsqCKwOBYGLLcJj6ir%2BWNBQmCYkvBCfmNHnN%2FWYyX2ZryVdpX2c7dQg75FkcOnmzfnezmQ0tqNlJpCl5BWErBkSkxNaE6hD09JbiboOm11sj55oAaTSz7RHyrO%2Bqab1AL3X3q%2BzhJxkE4r33vEoQzDOCciHC1IR0STi%2FURk64%2BvvEGTjRBqc56ppwesE4LsI1vE%2BuCAc86J2GcM6z8U2vdEbON3tWo4l7Kr7VHXXNN72wKj9QAhTlf3Mnvqi2KOZj%2BaBZZKyePTIKU%2BO4LHkGyumvCdsoJ89nGvmmHNWopzh9p6Lzl4psMKWdXpbn5wJgMZatr%2BGrCNXWZzu1lz7H8rB0bdh73XZP0%2B3JzoWndZ4OtSQ0gF7OG%2FaYiCqT9n9jql7qX5g66FrSAPo5ABwZU%2BH%2FyFT9jODC1EFXoQbQTxCskTG14asrw2SqaFY%2FeSm6V78cMm%2F%2FAA%3D%3D
Future[0]
Future[1]
Future[2]
Future[3]
CompositeFuture.any()
Success (250ms elapsed)
Failed (100ms elapsed)
Failed (450ms elapsed)
Success (150ms elapsed)
Failed (450ms elapsed)
직렬 구성: Compose
compose 를 사용하면 여러 Future<?>를 직렬로 구성할 수 있습니다.
직렬로 구성된 Future<?>는 순차적으로 실행되며 핸들러가 리턴되는 즉시 다음 Future<?>가 연쇄적으로 실행됩니다.
Future<Void> future0 = Future.future(prom -> someHandler0(prom));
Future<Void> future1 = Future.future(prom -> someHandler1(prom));
Future<Void> future2 = Future.future(prom -> someHandler1(prom));
Future<Void> composedFuture = future0.compose(v -> {
// future0가 리턴되면 future1가 실행
return future1;
}).compose(v -> {
// future1가 리턴되면 future2가 실행
return future2;
});
Future<?>가 순차적으로 실행되므로 성공 케이스의 실행 속도는 전체 Future<?>의 응답 시간의 합입니다.
https://viewer.diagrams.net/?tags=%7B%7D&highlight=0000ff&edit=_blank&layers=1&nav=1&title=%E1%84%86%E1%85%AE%E1%84%8C%E1%85%A6.drawio#R7VvbkqM2EP0aP3pLF66PO7ekUrupJFOV7DylNKAxSmHkArG29%2BsDRhg0MuCxB2OYfZpRS2qkVp9u9QHP8O1y80tMVsFX7tNwhoC%2FmeG7GUII2Eb2J5dsCwkEpltIFjHzpawSPLIftBwopSnzaaIMFJyHgq1UocejiHpCkZE45mt12AsP1aeuyIJqgkePhLr0H%2BaLoJA6yK7kv1K2CMonQ0vub0nKwXInSUB8vq6J8P0M38aci%2BK%2F5eaWhrn1SrsU8x4aevcLi2kkjpmAf2df%2FSRwnv9NU3f%2B91%2FbP59%2Bm9umXJzYljumfmYA2eSxCPiCRyS8r6Q3MU8jn%2BZqQdaqxnzhfJUJYSb8jwqxladJUsEzUSCWoeylGya%2B5dM%2FmbL1VOu520jNu8a2bEQi3tYm5c2nel81bdeq5vmfcz%2FImhGPaCF5YGEo%2B32SBLu95I8vjJFboNHIUpTwNPZom2Wx9FYSL6hoG2jsnSGDEeVLmi0%2FmxjTkAj2XV0Jke682I%2FbT%2F2Ds2yNCJTYc6TfSeTZGKgqioXJWZXfZP%2FUllGJdt70Fs%2BS%2B%2F9OwlTu4SEVaUxn5g2YmXea36letQ6YoI8rsrPxOgsuqgdJ3TQWdNN%2BVLphSwNh1UCGIdvrCucQSFlQw7gBms9CseKbTWaMzGTW8CazfsavnuKXfWz8cs6MX%2Bc5gN2MGXgNmMElqq8nzDgjM9nwYcaxxxNmhgkXjnlkuHCsIcNFucya73t8ueIJ9SUGhnZ%2B99rChWONzGTDhwtXv%2Fvq8aMCqheSJGGeahfViMciVbdRzQjmARuUsjOrDRu8uhmCV7YtAohWbWiKoGG0K%2Bq5bHH1O%2Fhj6nk0SQ5mgC%2FkmYbqwZGQLaL8VLOToXEmyH2beST8LDuWzPeLBEET9oM87%2FTlh7zKN7XbpnmT5%2BEWcEi6Q06e7UmGukO0uGYjlObgE3CR%2By4%2BMbfVGfzlJaG9HBoE6E2Ak5mxEW1KklTz54cBom13KOoZiBDoQTQvP8FyIkiUTtsGRdOGajScw%2FdxEvOg1gsAFbofLTO%2B5uFMdCIgDdShqG9Als%2BbamqUznmR3Hi51Liv4EZQuo6LIYNl7OqseSFquHVdpujdL%2FQQ44OugfExIVRi2%2FBVrzyyEdls%2BLIXIr14mnh2N0o3KZOyYZ2W3U2rQ1Hv2V1nxqaV3VHDe9ZxZ3ednGtD3JQLX6RGw9MJqA5FvQNRf6OFp1X4ooZXAP0XvnM4WOWL9LduHxSpnYXsqRTV5Stinc2A5rSg2vByv3%2BoIhcfVHsBqGKd6PigUDWtVwg79XqrQfXS11sMtTOdFlIxOOwo%2FSMVOoMlVXwAmD%2FJrXcht%2FCx369CfO4HrOeRDriFqMHXQNRYphr7roDcwi1fml6lza6A3MI6QdJ2K5gAuaVlf%2BfUizroUNR79tdpkmmRW4VzTozcwjoT0oa4Cd%2FDOwF08j384kjUaZBdHJ%2FQRdzuguKIPuvImtUv1Irh1Q%2F98P3%2F
Future[0]
Future[1]
Future[2]
Future[3]
composeFuture
Success (150ms elapsed)
Succes (50ms elapsed)
Success (100ms elapsed)
Success (30ms elapsed)
Success (Total 330ms elapsed)
실패 케이스의 실행 속도는 연쇄 실행 단계에서 가장 먼저 실패한 Future<?>의 응답 시간까지의 합입니다.
https://viewer.diagrams.net/?tags=%7B%7D&highlight=0000ff&edit=_blank&layers=1&nav=1&title=%E1%84%86%E1%85%AE%E1%84%8C%E1%85%A6.drawio#R7Vtbb9owFP41PDLFcZzLY6%2BbpnbaVmlbnyY3cYmnEKPEKdBfP4c4JK6TQKEQoH0CH19ifz7fuREG8GI8%2B5zgSXjLAhINTCOYDeDlwDRNw7HERy6ZFxJgIK%2BQjBIaSFkluKPPpBwopRkNSKoM5IxFnE5Uoc%2FimPhckeEkYVN12COL1KdO8IhogjsfR7r0Nw14WEhd06nkXwgdheWTgS3PN8blYHmSNMQBm9ZE8GoALxLGePFtPLsgUY5eiUsx77qld7mxhMR8nQnwG70N0tB9%2BJtl3vDXz%2FmP%2B69DB8nN8Xl5YhIIAGSTJTxkIxbj6KqSnicsiwOSL2uIVjXmhrGJEAIh%2FEc4n8vbxBlnQhTycSR7yYzyP%2Fn0T0i27ms9lzO58qIxLxsxT%2Ba1SXnzvt5XTVu0qnnBWa4HohmzmBSSaxpFsj%2FAabg4S%2F74AowcgVaQpShlWeKTLmSh1FacjAjvGmgtlUHQiLAxEdsXExMSYU6f1J1gqc6j5bjl1O%2BMij2aRsk9V%2BqdZJ4DDXWJYmNyVqU34kttG5VooU2v0Sx5%2FiccZfIM1xnPEjJA58YAXWp6p2rVNKSc3E3wAuOpMC6qBsm1ScLJrPuqdGBLgKAKkGXJ9rTiOTCkLKxx3DLa70JB8dWQWUcGmd0%2FZPaH%2FdqR%2FXLWtV%2FulvZrOwVw2jkDDoEzsGT14ZgZ98gg69%2FMuM7xmJl%2BzIWL1jQXrt2nuSi3WdN9n40nLCWB5EDfyu8dmrlw7SODrH9z4emxr24%2FKqL6EU5T6qu4qCCuy1QdoxoIqAGDUrZltoFsNTJEzgtsCwOiZRvaQsCyuhfacdriNcTgmEbiIpocwA1%2BIJF6bziiozi%2FVHExJBGCXLWpj6Mz2TGmQVD4B5LSZ%2FywWC%2B%2F40l%2BpsUp0Xnuhju4IasdcvJgWWOo60OHZrYyaWh8MjzTexOVGDrqDPb4mJKd3BkA3nvj28vsHpkb8s0yVyy0Y76B8nm1u7vLfJ%2Bk6WkwTirnXii3P8Yt48IjCIiPK%2B8Gpe1aGUkDs8WY7yeUXm60KY80DyGPRAAotq3%2FWFpe2RFh1n8wDUw9JDtx726ValI6ZcvezLsje8VCO%2Ffuer59Wt7dbPn15ri9u57ydzFO%2BsdWuimuUvWih85Ex1T5s3lau2KhnRNRr5MvcghjfDJMbCksVkxEDlCLC0PwJkoyBKhx2X0wVa%2Flv1Omrkxk16Wq4%2FSdEevVDIBOi6otPxnunqqmBxuX3QNVoV7oeKdU1YrFm4a3GlX3Hd5CoN3paTEVGs2KsnumArc3pwobiPlR3HqT4hZc9604ALd9LW67ogPsKNTArQs1DfhuVbWxkWoID6DSBTteZjt8AA%2Bg7AX1jO0jXtguC9fihX1n4VBP104rCS%2BU9lTiBdGs3s8vhld%2Fc4BX%2FwE%3D
Future[0]
Future[1]
Future[2]
Future[3]
composeFuture
Success (150ms elapsed)
Succes (50ms elapsed)
Failed (80ms elapsed)
Not reached
Failed (Total 280ms elapsed)
정리 및 복습
Future<?>는 아직 발생하지 않은, 또는 발생하지 않을 결과를 나타냅니다.
여러 개의 Future<?>에 대한 비동기 결과를 처리하는 방법은 크게 병렬 구성과 직렬 구성으로 가능합니다.
CompositeFuture.all
CompositeFuture.any
CompositeFuture.join
Compose
모든 Future<?>가 성공을 리턴하면 성공 콜백, 또는 하나의 Future<?>라도 실패를 리턴하면 실패 콜백
하나의 Future<?>라도 성공을 리턴하면 즉시 콜백, 또는 모든 Future<?>가 실패를 리턴하면 실패 콜백
모든 Future<?>가 성공을 리턴하면 성공 콜백, 또는 모든 Future<?>가 리턴하였으나 하나의 Future<?>라도 실패하였으면 실패 콜백
여러 Future<?>를 순차 실행하며, 실패를 리턴하면 나머지 Future<?>는 실행되지 않고 중단