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

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.
主站蜘蛛池模板: 宜都市| 城市| 西乌| 雷波县| 四子王旗| 榆社县| 赤壁市| 大荔县| 马边| 黄骅市| 绥滨县| 禄劝| 南开区| 北川| 兰坪| 元阳县| 册亨县| 庆云县| 伊春市| 江达县| 绥中县| 乌鲁木齐市| 五大连池市| 文安县| 来凤县| 顺义区| 赞皇县| 洪雅县| 东海县| 海南省| 佛学| 杭州市| 平果县| 阿瓦提县| 胶南市| 乳山市| 佛坪县| 浦东新区| 博爱县| 兴业县| 龙川县|