title: Should "next" always be invoked last in Redux middleware?
body: <p><strong>tl;dr: Within a Redux middleware function, is it okay to dispatch a new action after calling <code>next</code> to finish updating the store?</strong></p>
  
  <p>I'm building a HackerNews reader using <a href="https://flutter.io" rel="nofollow noreferrer">Flutter</a> and <a href="https://github.com/davidmarne/flutter_built_redux" rel="nofollow noreferrer">built-flutter-redux</a>, based off of Brian Egan's <a href="https://github.com/brianegan/flutter_architecture_samples" rel="nofollow noreferrer">TodoMVC example</a>. It uses HN's Firebase-backed API to pull data:</p>
  
  <p><a href="https://github.com/HackerNews/API" rel="nofollow noreferrer">https://github.com/HackerNews/API</a></p>
  
  <p>My actions look like this right now:</p>
  
  <pre><code>ActionDispatcher&lt;Null&gt; fetchHackerNewsTopStories;
  ActionDispatcher&lt;List&lt;int&gt;&gt; fetchHackerNewsTopStoriesSuccess;
  ActionDispatcher&lt;Null&gt; fetchHackerNewsTopStoriesFailure;
  ActionDispatcher&lt;Null&gt; fetchNextHackerNewsItem;
  ActionDispatcher&lt;HackerNewsItem&gt; fetchHackerNewsItemSuccess;
  ActionDispatcher&lt;Null&gt; fetchHackerNewsItemFailure;
  </code></pre>
  
  <p>There's a piece of middleware that listens for the <code>fetchHackerNewsTopStories</code> action and kicks off a call to the API:</p>
  
  <pre><code>MiddlewareHandler&lt;AppState, AppStateBuilder, AppActions, Null&gt;
  createFetchHackerNewsTopStories(HackerNewsRepository service) {
    return (MiddlewareApi&lt;AppState, AppStateBuilder, AppActions&gt; api,
        ActionHandler next, Action&lt;Null&gt; action) {
      service.fetchHackerNewsTopStories().then((ids) {
        return api.actions.fetchHackerNewsTopStoriesSuccess(ids);
      }).catchError(api.actions.fetchHackerNewsTopStoriesFailure);
  
      next(action);
    };
  }
  </code></pre>
  
  <p>When it returns, I update my app's state with the list of IDs.</p>
  
  <p>At some point I need to dispatch another action, <code>fetchNextHackerNewsItem</code>. There's another middleware function that will listen for that action and request the details for the the first story. When those details arrive, it'll request the next story, and so on until everything's updated.</p>
  
  <p>What I'd like to know is whether I can do this:</p>
  
  <pre><code>// Invoked when REST call for the list of top story IDs completes.
  MiddlewareHandler&lt;AppState, AppStateBuilder, AppActions, List&lt;int&gt;&gt;
  createFetchHackerNewsTopStoriesSuccess() {
    return (MiddlewareApi&lt;AppState, AppStateBuilder, AppActions&gt; api,
        ActionHandler next, Action&lt;List&lt;int&gt;&gt; action) {
      next(action);
      api.actions.fetchNextHackerNewsItem(); // Is this cool?
    };
  } 
  
  // Initiates a request for a single story's details.
  MiddlewareHandler&lt;AppState, AppStateBuilder, AppActions, Null&gt;
  createFetchNextHackerNewsItem(HackerNewsRepository service) {
    return (MiddlewareApi&lt;AppState, AppStateBuilder, AppActions&gt; api,
        ActionHandler next, Action&lt;Null&gt; action) {
      int nextId = api.state.topStoryIds[api.state.loadedUpToIndex];
      service.fetchHackerNewsItem(nextId).then((item) {
        return api.actions.fetchHackerNewsItemSuccess(item);
      }).catchError(api.actions.fetchHackerNewsTopStoriesFailure);
  
      next(action);
    };
  }
  </code></pre>
  
  <p>Because <code>createFetchNextHackerNewsItem</code> relies on the app's state (<code>api.state.topStoryIds[api.state.loadedUpToIndex]</code>), I'd like for it to run <em>after</em> the store is updated by the <code>next(action)</code> call.</p>
  
  <p>Is it cool to dispatch new actions in Redux middleware after calling <code>next</code>, or is that some kind of anti-pattern? If it <em>is</em> an anti-pattern, what's the best way to implement this flow?</p>