Skip to content

Return sealed RequestResult type from ImageLoader.execute(GetRequest).#349

Merged
colinrtwhite merged 12 commits into
masterfrom
colin/get_result_type
Apr 12, 2020
Merged

Return sealed RequestResult type from ImageLoader.execute(GetRequest).#349
colinrtwhite merged 12 commits into
masterfrom
colin/get_result_type

Conversation

@colinrtwhite
Copy link
Copy Markdown
Member

@colinrtwhite colinrtwhite commented Apr 5, 2020

This has two main benefits:

  • imageLoader.execute(GetRequest) is now safe by default. Consumers must handle the success/error case. This is more intuitive than having to surround the call in a try/catch.
  • We can provide more info in the returned value (e.g. the source of the image).

This PR also adds DataSource.MEMORY_CACHE to indicate if a request is fulfilled from an ImageLoader's internal memory cache.

Fixes #278.

@colinrtwhite colinrtwhite force-pushed the colin/get_result_type branch 2 times, most recently from b7af743 to fb5a57c Compare April 6, 2020 00:24
data class ErrorResult(
override val drawable: Drawable?,
val throwable: Throwable
) : RequestResult()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these still usable in Java?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! Sealed classes are Java compatible.

@colinrtwhite colinrtwhite force-pushed the colin/get_result_type branch 2 times, most recently from 295c8f1 to 1e3e07d Compare April 9, 2020 20:09
@colinrtwhite colinrtwhite force-pushed the colin/get_result_type branch from 1e3e07d to 558f6c7 Compare April 11, 2020 07:22
@colinrtwhite colinrtwhite merged commit b404dfe into master Apr 12, 2020
@colinrtwhite colinrtwhite deleted the colin/get_result_type branch April 12, 2020 02:53
colinrtwhite added a commit that referenced this pull request Oct 5, 2022
#349)

* Return sealed RequestResult type from ImageLoader.execute(GetRequest).

* Docs.

* Docs.

* Delete test code.

* Clean imports.

* Docs.

* Docs.

* Update deprecation expression.

* Add context parameter to GetRequest.

* Update API.

* Re-add deprecated constructor.

* Update docs.
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

Successfully merging this pull request may close these issues.

[FR] Expand return type on imperative APIs

2 participants