Skip to content

Instantly share code, notes, and snippets.

@vgrichina

vgrichina/booking.ts

Last active Nov 28, 2018
Embed
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.
assert_has_mana(6);
let hotelBooking = bookHotel.withMana(3).withCoins(1000).book(sender());
let trainBooking = bookTrain.withMana(3).withCoins(1000).book(sender());
Promise.all(hotelBooking, trainBooking)
.withMana(7)
.catch(_bookingFailed.bind(sender(), /* whatever info about "session" needed */));
.withMana(1)
.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>) {
bookHotel.withMana(3).cancel(client);
bookTrain.withMana(3).cancel(client);
client.onBookingFailed(...);
}
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.