title: Better alternative to using concatMap twice within pipe?
body: <p>I want to execute a pre-defined promise (promise 2) recursively after another promise (promise 1) resolves to see when my connection to a peripheral device returns false, following which I can do something else.  I'd like to be able to do so using observables.  Here's the code I've come up with so far and have 2 questions:</p>
  <p><em>1) Is there a better alternative to using concatMap twice in my code in the <strong>reprovision()</strong> function</em>,</p>
  <p>and</p>
  <p><em>2) Is there a better way to implement my code to do what I've described above</em>?</p>
  <p>Here's the code which uses observables to execute promise 1 (only once) and promise 2 recursively and then does something with the result:</p>
  <pre><code>reprovision(){
      this.bleMessage = this.prepareMessageService.prepareMessage(
        MessageCategory.customAction, CustomActionConstants.reboot, this.customPayload
      );
  
      from(this.bleService.bleWrite('custom', this.bleMessage)).pipe(
        concatMap(x =&gt; interval(1000)),
        concatMap(x =&gt; this.bleService.checkBleConnection1(this.deviceId)),
        takeWhile(x =&gt; x, true)).subscribe(
          resp =&gt; console.log('still connected to peripheral'),
          err =&gt;  {
            console.log('disconnected from peripheral, do something else');
          }
        );
  }
  </code></pre>
  <p>Here's the code for promise 2 (this.bleService.checkBleConnection1), which I want executed recursively until the peripheral is disconnected from my mobile device.  The idea behind this promise is that it should resolve as long as my mobile device is still connected to a peripheral, and throw an error once that connection fails.</p>
  <pre><code>checkBleConnection1(deviceId: string){
    return BleClient.getConnectedDevices([]) //BleClient.getConnectedDevices([]) returns a promise
    .then(resp =&gt; {
      if (!resp.some(elem =&gt; deviceId === elem.deviceId)){
        throw new Error('Peripheral connection failed');
      }
      return true;
    })
    .catch(error =&gt; {
      throw error;
    });
  }
  </code></pre>