10 examples of 'go defer' in Go

Every line of 'go defer' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Go code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
203func (c *Cmd) Defer(vars *Vars) interface{} {
204 p := c
205 for {
206 if p.ParentFunc != nil {
207 if p.ParentFunc.Defers == nil {
208 p.ParentFunc.Defers = []*Cmd{c.Params[0]}
209 } else {
210 p.ParentFunc.Defers = append([]*Cmd{c.Params[0]}, p.ParentFunc.Defers...)
211 }
212 break
213 }
214 if p.ParentCmd == nil {
215 break
216 }
217 p = p.ParentCmd
218 }
219 return nil
220}
70func (this *Route) DeferFunc(f web.RequestHandler) {
71 this._routeMap.DeferFunc(f)
72}
71func testDefer() {
72 i := 1
73 defer deferred("...run as defer", i)
74 i++
75 defer func() {
76 println("...run closure deferred:", i)
77 }()
78 i++
79 defer deferred("...run as defer", i)
80 i++
81
82 var t Printer = &Thing{"foo"}
83 defer t.Print("bar")
84
85 println("deferring...")
86}
45func defer_test() {
46 ch := make(chan int)
47
48 for i := 0; i < 10; i++ {
49 go defer_test_fun(i, ch)
50 }
51 for i := 0; i < 10; i++ {
52 if v, ok := <- ch; ok {
53 fmt.Println("got the exited chan:", v, ok)
54 }
55 }
56 time.Sleep(3 * time.Second)
57 fmt.Println("quit")
58}
176func (c *Compo) Defer(fn func(Context)) {
177 c.dispatcher().Dispatch(func() {
178 if !c.Mounted() {
179 return
180 }
181 fn(makeContext(c.self()))
182 })
183}
849func When(d ...interface{}) Deferred {
850 return Deferred{js.Global.Get(JQ).Call("when", d...)}
851}
83func (linker *Linker) addDeferReturn(_func *_func) (err error) {
84 return nil
85}
205func (this *sqlUpdater) appendDefer(wb *record) {
206 //为了防止错误重置writeback标记,需要核对版本号
207 wb.ckey.clearWriteBack(wb.writeBackVer)
208 recordPut(wb)
209}
83func (tp *FixedPool) Go(f func()) {
84 if atomic.LoadInt32(&tp.stopped) == 1 {
85 return
86 }
87 tp.push(f)
88}
234func (this *Converter) converterDefer() {
235 //删除不必要的文件
236 os.RemoveAll(filepath.Join(this.BasePath, "META-INF"))
237 os.RemoveAll(filepath.Join(this.BasePath, "content.epub"))
238 os.RemoveAll(filepath.Join(this.BasePath, "mimetype"))
239 os.RemoveAll(filepath.Join(this.BasePath, "toc.ncx"))
240 os.RemoveAll(filepath.Join(this.BasePath, "content.opf"))
241 os.RemoveAll(filepath.Join(this.BasePath, "titlepage.xhtml")) //封面图片待优化
242 os.RemoveAll(filepath.Join(this.BasePath, "summary.html")) //文档目录
243}

Related snippets