Comments (10)
@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.
@svanharmelen I appreciate your input here as well.
from azure-sdk-for-go.
@ahmetalpbalkan overall approach sounds good to me. Do have 2 questions/remarks...
- 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, ifok
inerr, ok := <-errCh
will ever be anything else thannil
in this example? It seems that even if it's cancelled it will still benil
. - 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.
- You're right I'm overengineering here I guess. We can still return
error
from the method and yet can still support cancellation. - 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.
@svanharmelen check this, much simpler: http://play.golang.org/p/FxzU8d7Xbs
from azure-sdk-for-go.
That last one is pretty cool. I'm all for it.
from azure-sdk-for-go.
Yes, that looks a lot cleaner to me as well...
from azure-sdk-for-go.
Sent PR for this at #137.
from azure-sdk-for-go.
Hi,
Have you considered go's context for cancellation? It looks really easy to use :)
from azure-sdk-for-go.
@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)
- Support update container registry cache rule source repository and target repository HOT 2
- [Question] How does token Caching work HOT 5
- [azeventhubs] NextPartitionClient does not always respect context cancellation HOT 3
- [azcosmos] 1.0.3 - The provided cross partition query can not be directly served by the gateway HOT 4
- Question: How can I count the number of blobs in a storage container? HOT 3
- DownloadFile without Range.Count incurs 2 calls to GetProperties HOT 2
- Update the doc of InteractiveBrowserCred and DeviceCodeCred
- Pagination of Availability Statuses does not work
- Go SDK for commercial-marketplace-client HOT 1
- Clean up track1 tool in eng/tools
- service Package HOT 1
- Download a specific version from Azure blob HOT 3
- Allow expiring authorization token for 403 response HOT 6
- Allow passing any policy on individual request done with a client HOT 1
- Cloud Shell ManagedIdentitySource should throw if a user-assigned managed identity clientID or resourceID is supplied
- Port AuthenticationRecord related caching doc HOT 1
- [Identity] AzurePipelinesCredential parameterless constructor and add to DAC HOT 1
- [Identity] Create a new credential to support FIC in Github Actions HOT 1
- Add tracing to the Cosmos Client HOT 2
- ARM Resource Health NewEmergingIssuesClient().NewListPager NextPage is failing to unmarshall armresourcehealth.EmergingIssue.RefreshTimestamp HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from azure-sdk-for-go.