本文整理汇总了Golang中github.com/ipfs/go-ipfs/core.IpfsNode.Closing方法的典型用法代码示例。如果您正苦于以下问题:Golang IpfsNode.Closing方法的具体用法?Golang IpfsNode.Closing怎么用?Golang IpfsNode.Closing使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/ipfs/go-ipfs/core.IpfsNode
的用法示例。
在下文中一共展示了IpfsNode.Closing方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Serve
func Serve(node *core.IpfsNode, lis net.Listener, options ...ServeOption) error {
handler, err := makeHandler(node, options...)
if err != nil {
return err
}
addr, err := manet.FromNetAddr(lis.Addr())
if err != nil {
return err
}
// if the server exits beforehand
var serverError error
serverExited := make(chan struct{})
node.Children().Add(1)
defer node.Children().Done()
go func() {
serverError = http.Serve(lis, handler)
close(serverExited)
}()
// wait for server to exit.
select {
case <-serverExited:
// if node being closed before server exits, close server
case <-node.Closing():
log.Infof("server at %s terminating...", addr)
lis.Close()
outer:
for {
// wait until server exits
select {
case <-serverExited:
// if the server exited as we are closing, we really dont care about errors
serverError = nil
break outer
case <-time.After(5 * time.Second):
log.Infof("waiting for server at %s to terminate...", addr)
}
}
}
log.Infof("server at %s terminated", addr)
return serverError
}