Skip to content

More complex serialForEach example #10

@scottsd

Description

@scottsd

Hello,

I'm trying to put together a more complex serialForEach example, which includes "jumping" manually to next step, based on the example in issue #3.
step 1: search for the value
step 2: if found, just go to next step. If not, search again using different parameters, and go to next step using that value


flow.serialForEach(["refe", "lkajdflkjwernm", "crypto", "poidfgmnermn"], function(val) {
  console.log("Searching for " + val)
      $.ajax({
                type: "GET",
        url: 'https://api.stackexchange.com/2.1/badges?key=U4DMV*8nvpm3EOpvf69Rxw((&site=stackoverflow&order=desc&sort=rank&filter=default',
        data: {inname: val},
                success: this
      })

},function(search_result) {
  console.log('search_result')  
  console.log(search_result)

  var next = this
  if (search_result.items.length > 0) {
    console.log('found')  
    next(search_result.items[0])
  } else {
    console.log('NOT found')  
    //just get the latest badge
      $.ajax({
                type: "GET",
        url: 'https://api.stackexchange.com/2.1/badges?key=U4DMV*8nvpm3EOpvf69Rxw((&site=stackoverflow&order=desc&sort=rank&filter=default',
        data: {},
                success: this
      })

  }

},function(badge) {
  console.log('badge')  
  console.log(badge)  



},function() {
    console.log('This is the end!');
});

There are multiple issues with this sample:

  1. the 'badge' step isn't called with additional data passed as parameters. 'badge' is always undefined.
  2. processing stops after 2nd value in serialForEach array
  3. 'This is the end!' never makes it

How should the code look for this to work?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions