title: How can I emit an action and a stream in the same epic in redux-observable?
body: <p>I'm trying to upgrade my <code>executeWithRetries</code> utility (see below) to the most recent version of <code>redux-observable</code> where dispatching within an epic is no longer allowed.</p>
  
  <p>Currently, this utility sees whether a required token is expired, and if so, it dispatches a <code>REFRESH_TOKEN</code> action and returns a new <code>action$</code> which responds to the resulting <code>REFRESH_TOKEN_SUCCESS</code> action by performing the original request, with the new token included. This works correctly.</p>
  
  <p>Without dispatching the action explicitly, how can I both:</p>
  
  <ol>
  <li>trigger the <code>REFRESH_TOKEN</code> action and also</li>
  <li>create a stream that responds to another (resulting) action?</li>
  </ol>
  
  <pre class="lang-js prettyprint-override"><code>import {isEmpty} from 'ramda';
  import { of } from 'rxjs/observable/of';
  import {
    actions as guestActions,
    selectApiKey,
    selectGuestRefreshToken,
    selectGuestTokenExpiryMs,
    types as guestTypes,
  } from '../reducers/guest';
  
  const retryOrFail = ({ requestFactory, failure, success, store }) =&gt; {
    const state = store.getState();
    const apiKey = selectApiKey(state);
    const tokens = { apiKey, accessToken };
    return requestFactory.retry(tokens)
      .map(res =&gt; {
        return success(res);
      })
      .catch(err =&gt; {
        return retryOrFail({ requestFactory, failure, success, store });
      });
  };
  
  const refreshTokensIfNecessary = (store) =&gt; {
    const state = store.getState();
    const guestRefreshToken = selectGuestRefreshToken(state);
    const guestTokenExpiryMs = selectGuestTokenExpiryMs(state);
    const { dispatch } = store;
  
    const guestTokenExpired = () =&gt; guestRefreshToken &amp;&amp; guestTokenExpiryMs &amp;&amp; guestTokenExpiryMs &lt; Date.now();
  
    if (guestTokenExpired()) {
      dispatch(guestActions.refreshToken(guestRefreshToken));
      return true;
    }
    return false;
  }
  
  export default function executeWithRetries({ requestFactory, success, failure, store, action$ }) {
    const retryAction = action$.ofType(
      guestTypes.REFRESH_TOKEN_SUCCESS
    )
      .take(1)
      .switchMap(() =&gt; retryOrFail({ requestFactory, failure, success, store }));
  
    if (refreshTokensIfNecessary(store)) {
      return retryAction;
    }
  
    return requestFactoryToUse.execute()
      .map(res =&gt; success(res))
      .catch((err) =&gt; {
        return of(failure(err.toString()));
      });
  }
  </code></pre>
  
  <p>It may be that this code is structured in a way that is no longer compatible with <code>redux-observable@latest</code>, since it is relying on dispatching an action, but I don't know of an alternative way to handle this case.</p>