Unverified Commit 7144be54 authored by Niklas Adolfsson's avatar Niklas Adolfsson Committed by GitHub
Browse files

rpc module: refactor subscriptions to return `impl IntoSubscriptionResponse` (#1034)



* refactor subscription to return `Option<Result<>>`

* address grumbles: change to Result<(), Option<M>>

This changes the subscription API again to return `Result<(), Option<SubscriptionMessage>>`
to work a little smoother with the combinators and it introduces an extention trait
to make convert it `Result<T, Error>` to `Result<T, Option<SubscriptionMessage>>`

This trait is implemented for types where it is possible and for custom types and tricky situations the
user has to implement themselves.

For instance it's not possible to implement on `TrySendError` because that depends on the use-case
i.e. whether the channel is full should be regarded as an error or not.

* remove weird default errors

* fix tests

* revert weird trait

* introduce `IntoSubscriptionResult`

* refactor: introduce subscription mod

* impl StdError for subscription error types

* fix nits + tests

* fix doc tests

* remove deadcode

* Update server/src/tests/ws.rs

* cleanup to make review easier

* SubscriptionAcceptError -> PendingSubscriptionAcceptError

* make it clear that SubscriptionPermit is mocked

* remove deadcode

* fix doc links

* make register_subscription more readable

* remove Option impl for IntoSubscriptionCloseResponse

* fix tests

* add test for subscription return type

* fix nits

* impl `IntoSubscriptionCloseResponse` for ()

* remove useless ui test

* Update core/src/server/error.rs

* register_subscription: change order of parameters

* Update core/src/server/error.rs

* Update proc-macros/src/lib.rs

* fix doc link

* proc macro: compile test for !Result

* hacky solution

* add niklas ugly hack for providing default value

* fix hacks

* cargo fmt

* Update core/src/server/subscription.rs

Co-authored-by: default avatarJames Wilson <[email protected]>

* fix grumbles

* fix tests

* add test for null notification

* impl IntoSubscriptionResponse for Result<(), E>

* more descriptive error impls

* Update core/src/server/subscription.rs

Co-authored-by: default avatarJames Wilson <[email protected]>

* update docs: Subscription::next

* revert UI tests

* proc macro tests: add subscription -> ()

* remove unused tokio feature

* show failing test

* fix tests

* revert JSON str parsing

* add `SerializeAsStr` error

* show James

* push hack to show James what I mean

* SubscriptionResult = Result<(), StringError>

* fix tests

* address grumbles

* Update core/src/server/subscription.rs

* Update proc-macros/src/lib.rs

* Update proc-macros/src/lib.rs

* remove unused error variant SubscriptionCallbackError

---------

Co-authored-by: default avatarJames Wilson <[email protected]>
parent a0ce8d4c
Pipeline #256857 passed with stages
in 1 hour, 4 minutes, and 20 seconds