Delete file from evaluation

This commit is contained in:
priyeshmashelkar 2018-07-02 12:29:42 +01:00 committed by GitHub
parent 3e3e577eee
commit c7d58f3e58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 0 additions and 36 deletions

View File

@ -1,36 +0,0 @@
package com.baeldung.reactive.controller;
import java.math.BigDecimal;
import java.time.Duration;
import java.util.Random;
import java.util.stream.Stream;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baeldung.reactive.model.Stock;
import reactor.core.publisher.Flux;
import reactor.util.function.Tuple2;
@RestController
@RequestMapping("/rtes")
public class StockReactiveController {
@GetMapping(produces = MediaType.TEXT_EVENT_STREAM_VALUE, value = "/stocks/{code}")
public Flux<Stock> getStocks(@PathVariable String code) {
BigDecimal startingPrice = new BigDecimal("100");
Flux<Stock> stockFlux = Flux.fromStream(Stream.generate(() -> new Stock(code, getLatestPrice(startingPrice))));
Flux<Long> emmitFlux = Flux.interval(Duration.ofSeconds(1));
return Flux.zip(stockFlux, emmitFlux)
.map(Tuple2::getT1);
}
private BigDecimal getLatestPrice(BigDecimal startingPrice) {
BigDecimal priceChange = BigDecimal.valueOf(new Random().nextDouble());
return new Random().nextBoolean() ? startingPrice.add(priceChange) : startingPrice.subtract(priceChange);
}
}