Sorry - I meant ..."calling select once per line...." be a good point
On Fri, Jul 21, 2023 at 12:41 PM Gurunandan Bhat <gb...@pobox.com> wrote: > Hi, > > Are there any common patterns that standard and 3rd party library > functions use to implement cancelling a context passed to it? I have looked > at the source of exec.CommandContext and it starts the process and spawns a > goroutine that kills the process when ctx.Done() is closed. That looks > simple enough. > > It seems to me that the key to implementing cancellation enabled function > is to look at specific points inside the function where ctx.Done() is > checked for. As an example, if I want to create a cancellable function that > reads lines from a file, would select'ing on ctx.Done() be a good place? > > Thanks. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAA_NO6gXPuwoa%2BGLDzv46epVd_yY6C9msk_Xy_WU%3Dx5XPrwujw%40mail.gmail.com.