Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perform multiple simultaneous ajax calls and zip the results is not working #44

Open
augusto-altman opened this issue Jan 3, 2016 · 2 comments

Comments

@augusto-altman
Copy link

I'm trying to perform multiple simultaneous ajax request to a REST api and get a stream that emits a value with a data structure containing the data retrieved by all the responses altogether. For this I'm using zip but I'm getting the following exception from Bacon.js:
Uncaught Error: At least one EventStream required

As an example, below there is a simplified version of my code:

let profileStreams = [];
let profiles = {
  someURL: {
    href: 'www.google.com'
  },
  someOtherURL: {
    href: 'github.com'
  },
  yetAnotherURL: {
    href: 'twitter.com'
  }
};

for (let index in profiles) {
  profileStreams.push(
    b$.ajax({
      url: profiles[index].href
    }).map((profileObject) => {
      return {
        owner: index,
        profile: profileObject
      };
    })
  );
}

let allUrlsRetrievedAsArray = Bacon.zipAsArray(profileStreams);
@raimohanska
Copy link
Contributor

Use combineAsArray instead.

@augusto-altman
Copy link
Author

Using combineAsArray I didn't get the exception. The problem now is that whenever I get a value in the combined stream that value is an Array of EventStreams instead the an Array with the requests' responses. On the other hand when I use Bacon.fromPromise with my ajax requests instead of Bacon.$.ajax it works nice both with combine and with zip. So my guess here is that Bacon.$.ajax is doing some transformation behind the scene.

for (let index in profiles) {
    profileStreams.push(
      Bacon.fromPromise($.ajax({
        url: profiles[index].href
      })).map((profileObject) => {
        return {
          owner: index,
          profile: profileObject
        };
      })
    );
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants