-
-
Notifications
You must be signed in to change notification settings - Fork 18
Return Promise for set and remove #16
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could add here what was expect and/or allow to be resolved through the promise. Is it just a simple bool or do we allow implementer specific information to be returned?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good question and i though about that myself lately. Since the returned promise is just a placeholder for a value, i'd be great if the types of the actual value the placeholder will resolve to could be defined.
Maybe ask the authors of the PSR PHPDoc Standard?
For now, this should probably just stated in the description, eg.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if
true(orboolmore generally) is a good idea. In Redis cache, the returning values are responses directly from Redis server (int, string, etc.). In example, for successful save operation "OK" string is returned as Redis returns it.This is a general problem with
Promises, that function should be described withPromiseInterface(to make IDE life easier and ours too) but we don't have any knowledge then about the value returned by thisPromiseitself when fulfilled. I saw in few libraries that declared return value was:PromiseInterface|int|string. We can simplify this toPromiseInterface|mixed. This will help code completition ans also give some tip about value retrieved fromPromiseitself. Implementing libraries can then narrow the return value toPromiseInterface|stringorPromiseInterface|MyGreatClass.Just a suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like a good compromise 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maciejmrozinski It doesn't help code completion, as
mixedetc. isn't returned, it's the resolution value. The proper way is either using generics likePromise<int>or using@return intand an additional@promiseor@async. That way, also@throwscould be used. While this is a general problem in PHP, promises are that often in async programming that I think it's fine to introduce new PHPDoc tags for them.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the
Promise<int>notation but that is just personal 😄 . What is more important that we define here what the developer can be expected to get from the promise.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might not be the best place to discuss this topic. This probably more suited for a meta discussion. For now, i'd propose to simply define the the possible resolution values in the description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it just resolve to
nulland failure to store it in the cache be an exception?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is debatable, but psr/simple-cache as well as doctrine/cache return true/false for set and delete/remove.
https://github.com/php-fig/simple-cache/blob/master/src/CacheInterface.php#L29
https://github.com/php-fig/simple-cache/blob/master/src/CacheInterface.php#L41
https://github.com/doctrine/cache/blob/master/lib/Doctrine/Common/Cache/Cache.php#L77
https://github.com/doctrine/cache/blob/master/lib/Doctrine/Common/Cache/Cache.php#L86
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"There was an error, but I won't tell you where or why it failed."
The reason for PSR-16 not to use an exception was that a failing cache shouldn't interrupt your code and keep things working. In case of promises you can just not wait for the promise or subscribe to it's resolution at all if you don't care.