[스크랩] CompletableFuture & @Async

Completable futures with Spring async
12 Jun 2015

스프링 비동기와 자바8의 CompletableFuture
2016.04.24

[Java] CompletableFuture: 조합할 수 있는 비동기 프로그래밍
2015.04.12

restful api call rxjs loop state check

How to loop through response object obtained from REST API and display data in the view in angular 2

import {OnInit, Component} from '@angular/core';
import {TemperatureService} from './temperature.service'; // import service   
import {Temperature} from './temperature'; // import your model

@Component({
  providers: [TemperatureService], 
  template: `
<ul>   
  <li *ngFor="let device of devices">{{device.lapID}}</li>  
</ul>
 `    
})

export class TemperatureComponent implements OnInit{
  devices;
  errorMessage: string;

  constructor(private temperatureService: TemperatureService){}

  ngOnInit(){
    this.getDevices();
  }

  getDevices(){
    this.temperatureService.getDeviceIDS()
      .subscribe(
         devices => this.devices = devices,
         error => this.errorMessage = <any>error 
         // Store error message receiver from server
         );
  }   
}
import {Http, Response} from '@angular/http';
import {Injectable} from '@angular/core';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';

import {Temperature} from './temperature';

@Injectable()

export class TemperatureService{
   private deviceIDUrl = '/api/temperatures/';  // URL to web API
   constructor(private http: Http) { }

   // GET request To access data and specify observable type from model

  getDeviceIDS(): Observable<Temperature[]>{
    return this.http.get(this.deviceIDUrl)
     .map(this.extractData) // to check for the status code
     .catch(this.handleError); // to check error
  }

  // Extracts from response
  private extractData(res: Response) {
     if (res.status < 200 || res.status >= 300) {
       throw new Error('Bad response status: ' + res.status);
     }
    let body = res.json();
    return body.data || { };
  }

  // To handle Error
  private handleError (error: Response | any) {
    // In a real world app, we might use a remote logging infrastructure
    let errMsg: string;
    if (error instanceof Response) {
      const body = error.json() || '';
      const err = body.error || JSON.stringify(body);
      errMsg = `${error.status} - ${error.statusText || ''} ${err}`;
    } else {
      errMsg = error.message ? error.message : error.toString();
    }
    console.error(errMsg);
    return Observable.throw(errMsg);
  }
}
export class Temperature{
  deviceId: string;
}

RxJs: How to loop based on state of the observable?

var source = Rx.Observable.return({val: 0, counter: 3})
    .expand(value =>  {
      if(!value.counter) return Rx.Observable.empty();
      value.counter -= 1;
      if(!value.counter) value.val = 'YESS';
      return Rx.Observable.return(value)
    })
    .subscribe(value => console.log(value.counter ?
                                    'Counter: ' + value.counter :
                                    'Next: ' + value.val));

실행되는 코드

10 Need-to-Know RxJS Functions with Examples
August 16, 2016

특정 상태가 나올 때까지 http.fetch() 반복 호출

Angular 2 + rxjs – how return stream of objects fetched with several subsequent http requests
Observable Continue calling API and changing parameters based on condition
Loop until condition becomes true in RxJava
Rxjs: Repeat an Ajax Call Every X Seconds, but Wait for the Last One to Complete
RxJS, how to poll an API to continuously check for updated records using a dynamic timestamp

Rx.Observable.while(condition, source)
Rx.Observable.prototype.doWhile(condition)

Plunker – exhaustMap

이것이 정답이 아닐까!! – skipWhile/takeWhile

Rx.Observable.skipWhile(condition)
Nested skipWhile in rxjs

How to loop through response object obtained from REST API and display data in the view in angular 2

Fetching Data In Angular2


RxJS 사용법

RxJS Basic – 기초

http.fetch 사용법

정말 멋진 Fetch API!
2015/05/25

Use an HTTP Client to talk to a remote server

Using Angular 2’s HTTP Client to Interact with Servers

답글 남기기

아래 항목을 채우거나 오른쪽 아이콘 중 하나를 클릭하여 로그 인 하세요:

WordPress.com 로고

WordPress.com의 계정을 사용하여 댓글을 남깁니다. 로그아웃 / 변경 )

Twitter 사진

Twitter의 계정을 사용하여 댓글을 남깁니다. 로그아웃 / 변경 )

Facebook 사진

Facebook의 계정을 사용하여 댓글을 남깁니다. 로그아웃 / 변경 )

Google+ photo

Google+의 계정을 사용하여 댓글을 남깁니다. 로그아웃 / 변경 )

%s에 연결하는 중

%d 블로거가 이것을 좋아합니다: