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

Version 3 #377

Closed
wants to merge 105 commits into from
Closed

Version 3 #377

wants to merge 105 commits into from

Conversation

si3nloong
Copy link

@si3nloong si3nloong commented Aug 27, 2022

This is a draft PR for the upcoming release version v3, it will break and redesign the whole reactive API using the generics feature offered by Go 1.18. Technically, this PR will resolve issues #375 #250 #343, as well as some missing features such as #362 #347.

⚠️⚠️⚠️ This is still under heavy development, PR is just to keep track of the overall progression.

I'm trying to map the rxjs API design to this lib as much as possible

Alpha Version
CHANGELOG :

  • remove vendor packages and use go.mod instead
  • utilize generic to implement strong type
  • rework Observe API to let user to be able to control the subscription
  • set minimum go version to v1.19 (required Generics and sync.Pointer)
  • add test cases for every function
  • update README and API documentation

Beta Version
CHANGELOG :

Request for comments :

  • API look and feel

@si3nloong
Copy link
Author

si3nloong commented Aug 29, 2022

Proposal for changing observe API:

Current :

for v := range observable.Observe() {}

// OR 
obs := observable.Observe()
for {
   select {
   case item, ok :=<- obs:
   }
}

Proposed : this is highly inspired by rxjs API design

type Subscription interface {
   Unsubscribe()
}

observable[T].Subscribe(onNext func(T), onError func(error), onCompleted func()) Subscription

The current API is very confusing, users have no way to control the subscription (unsubscribe the stream when needed), and they required to handle the error or data manually. I suggested we move the abstraction into internal function, and expose only the required functions.

@si3nloong
Copy link
Author

si3nloong commented Aug 30, 2022

The new version of API will look like this. @teivah any comments atm?
rxgo.IObservable interface will be renamed as rxgo.Observable in the future. Currently, I try to remove the old codes part by part.

Screenshot 2022-08-30 at 11 08 40 AM

Note: This stream data flow will be processed synchronously, that's why the function named as SubscribeSync

@si3nloong si3nloong marked this pull request as draft August 30, 2022 03:42
@si3nloong
Copy link
Author

si3nloong commented Aug 31, 2022

There are significant changes in the API. For example,

Previous

rxgo.Defer([]Producer{func(ctx context.Context, next chan<- Item) {
	next <- Of(1)
	next <- Of(2)
	next <- Error(fmt.Errorf("some error"))
}})

Current

rxgo.Defer(func() rxgo.IObservable[uint] {
   return rxgo.Interval(1000)
})

AND creating an observable is as easy as :

newObservable(func(sub Subscriber[int]) {
  for i := 0; i < 10; i++ {
    Next[int](I).Send(sub)
    time.Sleep(time.Second)
  }
  Complete[int]().Send(sub)
})

@si3nloong
Copy link
Author

I took a look at this PR (massive work!), and I got curious about one thing - do you plan on porting the scheduler concept to rxgo as well? I would mainly find it useful to be able to mock/control time in my tests.

I will take a look on that after finish the general API, I think should be feasible.

@si3nloong
Copy link
Author

I'm IDLE for some time due to work, will continue on this, so far the basic functionality is OK to go atm.

@adhaamehab
Copy link

adhaamehab commented Feb 23, 2023

@si3nloong hello, is this PR still active? I would love to pick it up to get a feel about maintaining this package, but don't want to over step if you have timed plan to complete it.

@Olshansk
Copy link

@davidlondono @si3nloong Wanted to bump the thread to see if this PR will ever get picked up again.

@plastikfan
Copy link

I'm interested to know if this pull request is still thing as I am in the process of defining my own V3 which uses generics, not sure about the other issues that have been identfied because I'm not sure if they will affect what I need for my own projects.

@teivah teivah closed this Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Breaking change from one version to another. v3 RxGo v3.
Projects
None yet
7 participants