Created
April 7, 2017 18:55
-
-
Save JeremyLikness/e43913a51661c049ec840d8e6fbb0a5c to your computer and use it in GitHub Desktop.
Service to consume Azure app function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Injectable } from '@angular/core'; | |
| import { Observable, Subject } from 'rxjs/Rx'; | |
| import { Http, URLSearchParams } from '@angular/http'; | |
| export interface IBifurcation { | |
| r: number; | |
| x: number; | |
| } | |
| @Injectable() | |
| export class IterationsService { | |
| constructor(public http: Http) { } | |
| public generate(width: number): Observable<IBifurcation> { | |
| const rIterator = Observable.range(0, width - 1).delay(1).map(x => (4.0 * x) / width), | |
| sync = new Subject<IBifurcation>(); | |
| rIterator.subscribe(r => { | |
| const params = new URLSearchParams(); | |
| params.set('r', r.toString()); | |
| this.http.get('https://angularsvc.azurewebsites.net/api/xIterate', { | |
| search: params | |
| }).subscribe(res => { | |
| const result = res.json(); | |
| if (result && result.length) { | |
| result.forEach(x => sync.next({ r, x })); | |
| } | |
| }); | |
| }); | |
| return sync.asObservable(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment