Skip to content

Commit

Permalink
fix exit issue
Browse files Browse the repository at this point in the history
  • Loading branch information
zc2638 committed Apr 13, 2022
1 parent f634ffa commit 3252cef
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cmd/ddshop/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,16 @@ func NewRootCommand() *cobra.Command {
return err
}
fmt.Println()

ctx, cancelFunc := context.WithCancel(context.Background())
go func() {
for {
select {
case <-ctx.Done():
logrus.Warningf("context done")
return
default:
}
if err := Start(session); err != nil {
switch err {
case core.ErrorNoValidProduct:
Expand All @@ -84,8 +92,10 @@ func NewRootCommand() *cobra.Command {

select {
case err := <-errCh:
cancelFunc()
return err
case <-successCh:
cancelFunc()
core.LoopRun(10, func() {
logrus.Info("抢菜成功,请尽快支付!")
})
Expand Down

0 comments on commit 3252cef

Please sign in to comment.