Skip to content

Instantly share code, notes, and snippets.



Last active Nov 28, 2018
What would you like to do?
Booking train and hotel
book_train_and_hotel() : void { // Needs 6 MANA.
// 3 for train and callback and 3 for hotel and callback.
// E.g. book_train and book_hotel doesn't need additional mana, so only 1 MANA for a call.
// Callback may need 1 additional to cancel train or hotel booking if one of them failed.
let hotelBooking = bookHotel.withMana(3).withCoins(1000).book(sender());
let trainBooking = bookTrain.withMana(3).withCoins(1000).book(sender());
Promise.all(hotelBooking, trainBooking)
.catch(_bookingFailed.bind(sender(), /* whatever info about "session" needed */));
.then(_bookingCompleted.bind(sender(), /* whatever info about "session" needed */));
_bookingCompleted(client, /* session args */, hotel: HotelBookingResult, train: TrainBookingResult) {
// This sends event to original caller
client.onBookingCompleted(hotel, train);
_bookingFailed(client, /* session args */, errors: Array<Error>) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.