Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Concurrency for all, any, when #36

Closed
ghost opened this issue Apr 14, 2018 · 4 comments
Closed

Proposal: Concurrency for all, any, when #36

ghost opened this issue Apr 14, 2018 · 4 comments

Comments

@ghost
Copy link

ghost commented Apr 14, 2018

Proposal:

concurrency : UInt? = nil for all, any, when

ex: Lets say we want to make 1000 async requests, but with concurrency 10, i think this will be a useful feature

@ghost ghost changed the title Proposal: concurrency for all, any, when Proposal: Concurrency for all, any, when Apr 14, 2018
@shoumikhin
Copy link
Contributor

Hi @umbri,

The thing is ‘all’ and other extensions do not control the order in which the promises get resolved, nor run them either, but just wait for them. There’s even no guarantees if promises passed to ‘all’ will all be resolved on a concurrent queue simultaneously. It totally depends on how you created those promises and on which queue would you invoke the block which will eventually trigger ‘fulfill’ or ‘reject’ with a particular promise. The following discussion may also be helpful: #28 (comment)

Let us know if there’s anything still unclear, happy to elaborate.

Thanks.

@ghost
Copy link
Author

ghost commented Apr 17, 2018

Hi @shoumikhin

Thank you for a quick reply,

About my proposal,
I was sure that promise is not executed till you call .then on it, but after some tests I find my epic broken logic :)

  1. If above is true, then my proposal is useless
  2. If above is true, then I have one more question :)

How to create Promise like a closure, that will do something after invoke it example:

let closure = {
    print("I am closure")
}

... 

closure()
let promise = Promise {
    print("I am promise")
}

...

// only now it will be executed 
promise.then {

}

@ghost
Copy link
Author

ghost commented Apr 17, 2018

I think something like this will be a nice feature: https://github.com/mxcl/PromiseKit/blob/master/Sources/when.swift#L104

@shoumikhin
Copy link
Contributor

I don't think anything like that would be possible, because then just subscribes as an observer for a promise state and has no side-effects on the promise behavior, like triggering some work blocks associated with the promise. Plus, there're actually no such blocks that a promise keeps that can be somehow invoked later, to begin with.

Promise is an extremely small and simple abstraction. I imagine you could build something more sophisticated on top of it to allow such "cold" subscription. But there're no plans to overcomplicate the existing lib at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant