• TehPers@beehaw.org
    link
    fedilink
    English
    arrow-up
    1
    ·
    10 days ago

    How does this library handle control flow? For example, how can I fetch results from the DB, then for each result, execute one of several different pipelines depending on properties of that entity?

    • Aijan@programming.devOP
      link
      fedilink
      arrow-up
      2
      ·
      10 days ago

      You can handle complex branching using standard JavaScript. Since every pipeline is just a function returning data, you can use if/else or map to return different sub-pipelines and commands from within your logic functions. Here’s an example:

      const processUsersFlow = () => 
        effectPipe(
          fetchAllUsers,
          (users) => {
            const tasks = users.map(user => {
              if (user.isAdmin) return syncAdminPermissions(user); // Sub-pipeline
              if (user.isGuest) return cleanupGuestAccount(user);  // Sub-pipeline
              return notifyUser(user); // Simple Command
            });
      
            return Parallel(tasks); 
          }
        )();