question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

2.x: Custom stream types

See original GitHub issue

Intended as a discussion

We often find ourselves creating an observable somewhere and exposing it later. While this is fine for local construction+usage, we lose important behavioral information about upstream behavior when we expose these downstream. Two large examples of where we run into this are around threading and BehaviorSubject-backed Observables.

  • For threading, some streams might implicitly be acting on a specific scheduler. For instance, Retrofit 1 (and optionally on 2) will subscribeOn the returned stream before returning it to a background scheduler of some sort. We have some internal APIs for local storage that do the same. This information is lost to the consumer, who may either not observe on a main thread if necessary or try to force a background thread not knowing that they’re already on one.
  • For subjects, the behavior is useful information to the consumer but we don’t want to expose it as a Subject directly to avoid leaking its API and allowing downstream consumers to call their own events. The “behavior” portion is often an important detail that leads to subtle bugs when not actively accounted for.

For threading, one might expose the observable downstream as a “BackgroundObservable” of sorts. For BehaviorSubject-backed ones - BehaviorObservable. It would probably be shallow at best, but the only other thing I can think of to solve this would maybe be with annotations, which isn’t as nice as leveraging the type system.

My early thinking would be to basically copying how ObservableHide works, and impose our own tooling (lint, error-prone, etc) to try to enforce some level of protection if we recognize that a returned observable exhibits traits like what I mentioned above. Would be curious to know if and how others have handled this case. We have over a hundred engineers using a monorepo with extensive Rx APIs, so good documentation about the behavior of APIs is essential. A hide-style approach still induces some overhead though, and operators like map still upconvert the type to Observable even though it doesn’t change the behavior of the underlying stream (i.e. customObservable.map(_ -> stuff()) should ideally still be recognized as a CustomObservable type).

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
ZacSweerscommented, Jan 8, 2017

I am blind

0reactions
ZacSweerscommented, Jan 9, 2017

Alright, going to close this. Think to() and the approach above is probably going to get us the best mileage for now. Thanks for the discussion all

Read more comments on GitHub >

github_iconTop Results From Across the Web

Stream Input & Output - hacking C++
Custom I/O Custom · Example: Point Coordinate I/O Example · Stream Operators Operators · (Some) Standard Library Stream Types (Some) Standard Stream Types...
Read more >
ADTF: Demo Custom Stream Type Filters Plugin
Name, Demo Custom Stream Types Data Generator. CID, demo_custom_stream_types_generator.filter.adtf.cid. Description, Use this filter to generate data based ...
Read more >
Input/Output Streams
Data Type of Input. Extraction Operator ( >> ) distinguishes between character 2 and number 2 by right hand operand: If type char,...
Read more >
Extending the iostream library - Cay Horstmann
Not only can input and output be defined for new data types, but new stream classes that interact with new devices can be...
Read more >
Live inputs: Supported types - AWS Elemental Live
Media type Upstream system Type of input Protocol HLS HTTP or HTTPS server HLS network input http:// or https:// MPTS RTP host Network input rtp://...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found