- Distributed Computing with Go
- V.N. Nikhil Anurag
- 255字
- 2021-06-24 18:36:10
Serial task execution
Let's first implement a program that will execute all the tasks in a linear manner. Based on the code overview we discussed previously, the following code should be straightforward:
package main import ( "fmt" ) // Simple individual tasks func makeHotelReservation() { fmt.Println("Done making hotel reservation.") } func bookFlightTickets() { fmt.Println("Done booking flight tickets.") } func orderADress() { fmt.Println("Done ordering a dress.") } func payCreditCardBills() { fmt.Println("Done paying Credit Card bills.") } // Tasks that will be executed in parts // Writing Mail func writeAMail() { fmt.Println("Wrote 1/3rd of the mail.") continueWritingMail1() } func continueWritingMail1() { fmt.Println("Wrote 2/3rds of the mail.") continueWritingMail2() } func continueWritingMail2() { fmt.Println("Done writing the mail.") } // Listening to Audio Book func listenToAudioBook() { fmt.Println("Listened to 10 minutes of audio book.") continueListeningToAudioBook() } func continueListeningToAudioBook() { fmt.Println("Done listening to audio book.") } // All the tasks we want to complete in the day. // Note that we do not include the sub tasks here. var listOfTasks = []func(){ makeHotelReservation, bookFlightTickets, orderADress, payCreditCardBills, writeAMail, listenToAudioBook, } func main() { for _, task := range listOfTasks { task() } }
We take each of the main tasks and start executing them in simple sequential order. Executing the preceding code should produce unsurprising output, as shown here:
Done making hotel reservation. Done booking flight tickets. Done ordering a dress. Done paying Credit Card bills. Wrote 1/3rd of the mail. Wrote 2/3rds of the mail. Done writing the mail. Listened to 10 minutes of audio book. Done listening to audio book.
推薦閱讀
- Windows Server 2019 Cookbook
- Red Hat Enterprise Linux 8系統(tǒng)管理實(shí)戰(zhàn)
- SharePoint 2013 WCM Advanced Cookbook
- STM32庫(kù)開發(fā)實(shí)戰(zhàn)指南:基于STM32F4
- 巧學(xué)活用Windows 7
- VMware NSX Cookbook
- INSTANT Galleria Howto
- Red Hat Enterprise Linux 6.4網(wǎng)絡(luò)操作系統(tǒng)詳解
- Learning BeagleBone
- 大規(guī)模分布式系統(tǒng)架構(gòu)與設(shè)計(jì)實(shí)戰(zhàn)
- 大學(xué)計(jì)算機(jī)應(yīng)用基礎(chǔ)實(shí)踐教程(Windows 7+MS Office 2010)
- Learn Quantum Computing with Python and IBM Quantum Experience
- Android NDK Beginner's Guide
- 計(jì)算機(jī)系統(tǒng)平臺(tái)
- 鴻蒙應(yīng)用開發(fā)實(shí)戰(zhàn)