Coder Social home page Coder Social logo

completable-future's Introduction

Completable Future Workshop

  • delete the package 'solution'
  • run the tests and make them pass
  • Follow the hints you find in the source code of the exercises, for example Combining.java
  • good luck

Basics

  • completing with value
  • completing with exception

Combining

  • thenApply
  • thenRun
  • compose (aka flatMap)
  • CF0.fork{CF1,CF2}->join{cfResult}
  • anyOf and Either

Exceptions

  • catch() {log}
  • catch() {wrap exception in new one}
  • catch() {default value}
  • catch() {call another CF} / retry
  • finally {cleanup}

Thread Pools

  • launch on ForkJoinPool.commonPool
  • launch on dedicated thread pool
  • launch in parallel 2 steps
  • Complete a CF after a delay
  • Combine 2 CF, change what thread executes the BiFunction

Testing

  • mocks returning a CF: then complete/fail
  • mocks delaying response
  • integration testing with WireMock

Enrich Data

(sequential, or parallel ||)

  • a() || b() ==> AB(a,b)
  • a(), then b1(a) ==> AB(a,b)
  • a(), then b1(a) || c1(a) ==> ABC(a,b,c)
  • a(), then b1(a), then c2(a,b) ==> ABC(a,b,c)
  • a() || b() || c() ==> ABC(a,b,c)

Complex Real-Life Scenarios

  • HTTP-Message Bridge
    • from a HTTP request send message on request MQ
    • keep the connection open
    • complete the pending HTTP request
      • with the corresponding reply message received on a reply MQ (hint: CorrelationID pattern), or
      • with a message "Order in processing" if no reply message arrives in 3 seconds
  • Bidding
    • You receive a HTTP request with a List clientIDs
    • Within 5 seconds,
    • Every five seconds emit (log) a signal.
    • If a http req arrives with the next n 5 sec
  • merge data: get/put async
  • rate limiting over WebClient adapter
  • profiling

completable-future's People

Contributors

victorrentea avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.