Skip to content

Instantly share code, notes, and snippets.

@JeremyLikness
Created April 7, 2017 18:55
Show Gist options
  • Select an option

  • Save JeremyLikness/e43913a51661c049ec840d8e6fbb0a5c to your computer and use it in GitHub Desktop.

Select an option

Save JeremyLikness/e43913a51661c049ec840d8e6fbb0a5c to your computer and use it in GitHub Desktop.
Service to consume Azure app function
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