zipAsync
Function that takes two suspend functions and a zip function as parameters. It executes the suspend functions asynchronously and then applies the zip function to their results.
Example usage:
suspend fun fetchUser(): User = userService.getUser(userId)
suspend fun fetchUserAddresses(): List<Address> = addressService.getUserAddresses(userId)
val userData = zipAsync(
::fetchUser,
::fetchUserAddresses
) { user, addresses -> DetailedUser(user, addresses) }
// prints user data along with their addresses
println(userData)
Function that takes three suspend functions and a zip function as parameters. It executes the suspend functions asynchronously and then applies the zip function to their results.
Example usage:
suspend fun fetchUser(): User =
userService.getUser(userId)
suspend fun fetchUserAddresses(): List<Address> =
addressService.getUserAddresses(userId)
suspend fun fetchUserOrders(): List<Order> =
orderService.getUserOrders(userId)
val userData = zipAsync(
::fetchUser,
::fetchUserAddresses,
::fetchUserOrders
) { user, addresses, orders ->
DetailedUser(user, addresses, orders)
}
// prints user data along with their addresses and orders
println(userData)
Function that takes four suspend functions and a zip function as parameters. It executes the suspend functions asynchronously and then applies the zip function to their results.
Example usage:
suspend fun fetchUser(): User =
userService.getUser(userId)
suspend fun fetchUserAddresses(): List<Address> =
addressService.getUserAddresses(userId)
suspend fun fetchUserOrders(): List<Order> =
orderService.getUserOrders(userId)
suspend fun fetchUserPayments(): List<Payment> =
paymentService.getUserPayments(userId)
val userData = zipAsync(
::fetchUser,
::fetchUserAddresses,
::fetchUserOrders,
::fetchUserPayments
) { user, addresses, orders, payments ->
DetailedUser(user, addresses, orders, payments)
}
// prints user data along with their addresses, orders and payments
println(userData)
Function that takes five suspend functions and a zip function as parameters. It executes the suspend functions asynchronously and then applies the zip function to their results.
Example usage:
suspend fun fetchUser(): User =
userService.getUser(userId)
suspend fun fetchUserAddresses(): List<Address> =
addressService.getUserAddresses(userId)
suspend fun fetchUserOrders(): List<Order> =
orderService.getUserOrders(userId)
suspend fun fetchUserPayments(): List<Payment> =
paymentService.getUserPayments(userId)
suspend fun fetchUserNotifications(): List<Notification> =
notificationService.getUserNotifications(userId)
val userData = zipAsync(
::fetchUser,
::fetchUserAddresses,
::fetchUserOrders,
::fetchUserPayments,
::fetchUserNotifications
) { user, addresses, orders, payments, notifications ->
DetailedUser(user, addresses, orders, payments, notifications)
}
// prints user data along with their addresses, orders, payments and notifications
println(userData)
Function that takes six suspend functions and a zip function as parameters. It executes the suspend functions asynchronously and then applies the zip function to their results.
Example usage:
suspend fun fetchUser(): User =
userService.getUser(userId)
suspend fun fetchUserAddresses(): List<Address> =
addressService.getUserAddresses(userId)
suspend fun fetchUserOrders(): List<Order> =
orderService.getUserOrders(userId)
suspend fun fetchUserPayments(): List<Payment> =
paymentService.getUserPayments(userId)
suspend fun fetchUserNotifications(): List<Notification> =
notificationService.getUserNotifications(userId)
suspend fun fetchUserPreferences(): Preferences =
preferenceService.getUserPreferences(userId)
val userData = zipAsync(
::fetchUser,
::fetchUserAddresses,
::fetchUserOrders,
::fetchUserPayments,
::fetchUserNotifications,
::fetchUserPreferences
) { user, addresses, orders, payments, notifications, preferences ->
DetailedUser(user, addresses, orders, payments, notifications, preferences)
}
// prints user data along with their addresses, orders, payments, notifications and preferences
println(userData)
Function that takes seven suspend functions and a zip function as parameters. It executes the suspend functions asynchronously and then applies the zip function to their results.
Example usage:
suspend fun fetchUser(): User =
userService.getUser(userId)
suspend fun fetchUserAddresses(): List<Address> =
addressService.getUserAddresses(userId)
suspend fun fetchUserOrders(): List<Order> =
orderService.getUserOrders(userId)
suspend fun fetchUserPayments(): List<Payment> =
paymentService.getUserPayments(userId)
suspend fun fetchUserNotifications(): List<Notification> =
notificationService.getUserNotifications(userId)
suspend fun fetchUserPreferences(): Preferences =
preferenceService.getUserPreferences(userId)
suspend fun fetchUserContacts(): List<Contact> =
contactService.getUserContacts(userId)
val userData = zipAsync(
::fetchUser,
::fetchUserAddresses,
::fetchUserOrders,
::fetchUserPayments,
::fetchUserNotifications,
::fetchUserPreferences,
::fetchUserContacts
) { user, addresses, orders, payments, notifications, preferences, contacts ->
DetailedUser(user, addresses, orders, payments, notifications, preferences, contacts)
}
// prints user data along with their addresses, orders, payments, notifications, preferences and contacts
println(userData)