Code Monkey home page Code Monkey logo

Comments (10)

ahmetb avatar ahmetb commented on July 17, 2024

@paulmey I'm thinking about this and we can do something like for cancellation: http://play.golang.org/p/TgIwmKxsad Please review.

We can modify WaitAsyncOperation(opID) to take an extra cancellation chan. User is allowed to pass nil to chan (user doesn't want to use cancellation). Or if they want to use it, they must close the cancellation chan.

The return value from WaitAsyncOperation is chan error.

Scenario-1: User just waits forever

err := <-WaitAsyncOperation(opID, nil)

(in this case no cancellation would happen and err==nil would mean op was successful).

Scenario-2: User might want to use cancellation

cancelCh := make(chan struct{}) /// user might close(cancelCh) in some other goroutine...
err, cancelled := <-WaitAsyncOperation(opID, cancelCh)

(in this case err==nil might mean (a) wait cancelled (b) op was successful. That's where cancelled comes in, if it's true, means (a) otherwise means (b).)

from azure-sdk-for-go.

ahmetb avatar ahmetb commented on July 17, 2024

@svanharmelen I appreciate your input here as well.

from azure-sdk-for-go.

svanharmelen avatar svanharmelen commented on July 17, 2024

@ahmetalpbalkan overall approach sounds good to me. Do have 2 questions/remarks...

  1. Do I read/understand correctly that the return value of WaitAsyncOperation would be a channel? I would not do that and I also don't see why you would want to do that in this case? Why not just return an error and a bool? Seems much more appropriate and clear in relation to what your actually are trying to do here. Also wondering, while looking at the playground example, if ok in err, ok := <-errCh will ever be anything else than nil in this example? It seems that even if it's cancelled it will still be nil.
  2. Just for clarity and/or in case you are going to add it to the docs/comments... You write: "Or if they want to use it, they must close the cancellation chan", but of course sending a message to the channel will work just as well.

from azure-sdk-for-go.

ahmetb avatar ahmetb commented on July 17, 2024

@svanharmelen

  1. You're right I'm overengineering here I guess. We can still return error from the method and yet can still support cancellation.
  2. Closing channel is smarter, because that way multiple goroutines can wait on the same ch, and all will be closed, however if you do <-ch only one will be closed and others will be locked forever.

from azure-sdk-for-go.

ahmetb avatar ahmetb commented on July 17, 2024

@svanharmelen check this, much simpler: http://play.golang.org/p/FxzU8d7Xbs

from azure-sdk-for-go.

paulmey avatar paulmey commented on July 17, 2024

That last one is pretty cool. I'm all for it.

from azure-sdk-for-go.

svanharmelen avatar svanharmelen commented on July 17, 2024

Yes, that looks a lot cleaner to me as well...

from azure-sdk-for-go.

ahmetb avatar ahmetb commented on July 17, 2024

Sent PR for this at #137.

from azure-sdk-for-go.

mvanotti avatar mvanotti commented on July 17, 2024

Hi,

Have you considered go's context for cancellation? It looks really easy to use :)

from azure-sdk-for-go.

ahmetb avatar ahmetb commented on July 17, 2024

@mvanotti quite honestly we didn't. :-) Although I doubt use case within this library would go beyond a simple cancellation channel, if that is becoming the standard way between Go libraries and programs to operate on cancellation and pipelines, we'd love to use that as well.

Feel free to open up a proposal issue, or betterโ€“ prototype and send a pull request. :-)

from azure-sdk-for-go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.