Question: It is my first day with tf and keras. I had a quick tutorial which worked fine, but left me with a lot of questions.
Can someone show me how to get two data inputs instead of one?

```py
import keras
import numpy as np

model = keras.Sequential([keras.layers.Dense(units=1, input_shape=[1])])
model.compile(optimizer='sgd',loss='mean_squared_error')

xs = np.array([1,2,3,4,5,6,7], dtype=int) # input data 1
ys = np.array([8,11,14,17,20,23,26], dtype=int)

# formel is : 3*x+5

model.fit(xs, ys, epochs=500)

print(model.predict([10.0]))

```

Answer: 
IMO, it's better to handle the polling either through Promises or RxJS without mixing them. I'd illustrate using RxJS.

Try the following

1. Convert the promise to an observable using the RxJS [`from`](https://rxjs.dev/api/index/function/from) function.
2. Use RxJS functions like [`timer`](https://rxjs.dev/api/index/function/timer) or [`interval`](https://rxjs.dev/api/index/function/interval) to regularly emit a value on a fixed interval.
3. Use a higher order mapping operator like [`switchMap`](https://rxjs.dev/api/operators/switchMap) to map from the outer emission to your API call. Refer [here](https://stackoverflow.com/a/63685990/6513921) for a brief description about different types of higher order mapping operators.
4. Use two [`takeWhile`](https://rxjs.dev/api/operators/takeWhile) operators, one for each of your condition respectively, to complete the subscription.
5. Use [`filter`](https://rxjs.dev/api/operators/filter) operator to only forward the emissions that pass the condition.

```js
import { from } from 'rxjs';

fetchData(id: any): Observable<any> {  // <-- return an observable
  return from(apiCall);                // <-- use `from` to convert Promise to Observable
}

```

```js
import { timer } from 'rxjs';
import { filter, switchMap, takeWhile } from 'rxjs/operators';

timer(0, 5000).pipe(                        // <-- poll every 5 seconds
  takeWhile((index: number) => index < 20)  // <-- stop polling after 20 attempts
  switchMap((index: number) => 
    this.someService.apiCall(index+1)       // <-- first emission from `timer` is 0
  ),
  takeWhile(                                // <-- stop polling when a condition from the response is unmet
    (response: any) => response.someValue !== someOtherValue,
    true                                    // <-- emit the response that failed the test
  ),
  filter((response: any) => 
    response.someValue === someOtherValue   // <-- forward only emissions that pass the condition
  )
).subscribe({
  next: (response: any) => {
    // handle response
  },
  error: (error: any) => {
    // handle error
  }
});

```

Edit: The condition in the 2nd `takeWhile` was doing the opposite of the requirement. I've adjusted the condition and included the `inclusive=true` argument. Thanks @Siddhant in the comments.
I know you've specified using rxjs, however you've also specified that `fetchData()` returns a `promise` and not an `observable`. In this case I would suggest using `async` and `await` rather than rxjs.

```js
  async retryFetch() {
    let counter = 0;
    while (counter++ < 20 && !this.data) {
      this.data = await this.fetchData(counter);
    }
  }

```

You can put whatever you want in the conditional.

Even if your api call returned an observable, I would still suggest wrapping it in a promise and using this very readable solution.

The stackblitz below wraps a standard `http.get` with a promise and implements the above function. The promise will randomly return the data or undefined.

<https://stackblitz.com/edit/angular-ivy-rflclt?file=src/app/app.component.ts>