- 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.
推薦閱讀
- Linux網絡管理與配置(第2版)
- 從零開始寫Linux內核:一書學透核心原理與實現
- 移動應用UI設計模式(第2版)
- Learning Bootstrap
- Windows 7中文版從入門到精通(修訂版)
- 一學就會:Windows Vista應用完全自學手冊
- NetDevOps入門與實踐
- OpenSolaris設備驅動原理與開發
- Django Project Blueprints
- Cassandra 3.x High Availability(Second Edition)
- 新編電腦辦公(Windows 10+ Office 2013版)從入門到精通
- Java EE 7 Developer Handbook
- Mastering Sass
- Windows 8玩全不求人
- STM32庫開發實戰指南