Giter VIP home page Giter VIP logo

Comments (5)

d-exclaimation avatar d-exclaimation commented on May 24, 2024 1

I might try to make a separate package for this and maybe make AsyncPubSubBase protocol so that you can build something that will have similar API to AsyncPubSub, but I can't make any guarantees for that.

I have a working solutions for the public protocol from AsyncPubSub so that you can build a custom pubsub implementation with similar API to AsyncPubSub. More details on the changes is on #45

The changes are not final yet, I might change my mind on it to make it simpler. Would appreciate your thoughts on it.

from pioneer.

d-exclaimation avatar d-exclaimation commented on May 24, 2024

It's very much possible. Pioneer can take any EventStream created from any AsyncSequence. Looking at this page of the Vapor docs, subscribing to a channel looked like

app.redis.subscribe(
  to: "channel_1", "channel_2",
  messageReceiver: { channel, message in
    switch channel {
    case "channel_1": // do something with the message
    default: break
    }
  },
  onUnsubscribe: { channel, subscriptionCount in
    print("unsubscribed from \(channel)")
    print("subscriptions remaining: \(subscriptionCount)")
  })

which is easy to translate to AsyncStream.

AsyncStream { con in
    app.redis.subscribe(
        to: ...,
        messageReceiver: { _, message in
            con.yield(message)
        },
        onUnsubscribe: { _, _ in
            con.finish()
        })
    
    ...
}

I think implementing something from that which have similar API to AsyncPubSub should be relatively straightforward. All you need to is to make a struct, wrap that code above into a method for the struct named asyncStream, and wrap the RediStack publish method into a method as well named publish.

The only problem is that I don't think it belong here. It make more sense as a separate package.

AsyncPubSub is provided in this library because I wanted to provide at least a basic in memory solution for Pub/Sub that can be used to start with immediately without extra setup.

from pioneer.

d-exclaimation avatar d-exclaimation commented on May 24, 2024

I might try to make a separate package for this and maybe make AsyncPubSubBase protocol so that you can build something that will have similar API to AsyncPubSub, but I can't make any guarantees for that.

from pioneer.

cshadek avatar cshadek commented on May 24, 2024

I agree. I think this approach makes a lot of sense.

from pioneer.

d-exclaimation avatar d-exclaimation commented on May 24, 2024

I think the PubSub protocol should be available in v0.8.0. Theres should also be part of documentation that explains a bit more about creating a custom PubSub implementation.

from pioneer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.