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

Multi/Parallel calls #31

Closed
icebob opened this issue May 24, 2017 · 3 comments
Closed

Multi/Parallel calls #31

icebob opened this issue May 24, 2017 · 3 comments

Comments

@icebob
Copy link
Member

icebob commented May 24, 2017

Solution 1 (with array)

broker.mcall([
	{ action: "posts.find", params: {limit: 5, offset: 0}, options: { timeout: 500 } },
	{ action: "users.find", params: {limit: 5, sort: "username"} }
]).then(results => {
	let posts = results[0];
	let users = results[1];
})

Solution 2 (with object)

broker.mcall({
	posts: { action: "posts.find", params: {limit: 5, offset: 0}, options: { timeout: 500 } },
	users: { action: "users.find", params: {limit: 5, sort: "username"} }
}).then(results => {
	let posts = results.posts;
	let users = results.users;
})
@chameleonbr
Copy link

Hey you could call using Promise.all:

let methods = [
broker.call('posts.find',{param1:'1'}), 
broker.call('users.find',{param1:'1'})
]

Promise.all(methods).then((arr)=>{
let posts = arr[0]
let users = arr[1]
})
// or
Promise.all(methods).then(([posts,users])=>{
// use the vars posts and users
})

@icebob
Copy link
Member Author

icebob commented Jul 13, 2017

Thank you. I know, but I want a comfortable method for this :) But it has low priority because there are other solutions.

icebob added a commit that referenced this issue Aug 9, 2017
@icebob
Copy link
Member Author

icebob commented Aug 10, 2017

@icebob icebob closed this as completed Aug 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants