官术网_书友最值得收藏!

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.
主站蜘蛛池模板: 汉中市| 日喀则市| 日土县| 大理市| 三明市| 共和县| 拜城县| 昭觉县| 扎鲁特旗| 全南县| 乐平市| 林州市| 吕梁市| 长治市| 河西区| 新晃| 吉木萨尔县| 江津市| 闽侯县| 道真| 昌宁县| 介休市| 绩溪县| 双桥区| 弥勒县| 通榆县| 绥芬河市| 洛宁县| 营口市| 怀远县| 大丰市| 长治县| 汉寿县| 固镇县| 宝兴县| 克什克腾旗| 福清市| 太仓市| 卓尼县| 东台市| 临海市|