Giter VIP home page Giter VIP logo

Comments (7)

aellwein avatar aellwein commented on August 9, 2024

@chrysn
WDYT maybe it is a good idea to introduce an additional cancel_observation method on ObservableResource to notify the resource about observe cancellation? Just to keep it symmetric to the existing add_observation handler?

from aiocoap.

chrysn avatar chrysn commented on August 9, 2024

Removal of observations generally happens via the cancellation callback passed to the ServerObservation's accept method; this allows an observation to be properly cancelled (pending bugs like this one, when cancellation_callback is probably not properly called, haven't looked properly yet), even when for example it has changed its path in the meantime. (Not a situation I'd expect to be common, but possible for kind of dynamic resources.) When add_obsevation is called, eg. on a Site, the ServerObservation is passed around until it gets accepted by a resource object, and I'm in favor of establishing the relationship to that object at accept time instead of hoping that a parallel cancel_observation would find its way to the very object the add_observation found, however likely it is in most cases.

Do you have a suggestion on how to fix this bug that would be made easier if there were a cancel_observation?

from aiocoap.

aellwein avatar aellwein commented on August 9, 2024

What i am actually trying to do is to establish a producer for an observation, which is to be notified via cancel_observation (server-side cancellation, not self-triggered) to not produce the notifications anymore (by using asyncio loop, my producer just reschedules itself periodically).

With no expectation of corner cases here i am currently not aware of, i would try a naive approach of looking up the cancel_observation attribute on a ObservableResource (by convention). If this one is present, it is to be called, i think after calling remove() on the server observation. But as i said, just a naive approach, maybe it makes much more sense to somehow let the resource keep the server observation until a cancellation is needed.

from aiocoap.

aellwein avatar aellwein commented on August 9, 2024

You may close the issue, if you think that such a callback is not necessary.

from aiocoap.

chrysn avatar chrysn commented on August 9, 2024

I see now what you are aiming for (the resource implementation needs to know when it is being observed, eg. to establish a fnotify); in light of that, my previous answer was not exactly to point.

To give me some leeway in how to implement observations, I try to keep the ServerObservation objects out of the ObservableResource as far as possible; a .cancel_observation would be possible, but as long as the actual question is "am i being observed", would a .update_observation_count (called with 0 or non-zero) method work for you?

from aiocoap.

aellwein avatar aellwein commented on August 9, 2024

Yes, this is exactly what i am looking for.

from aiocoap.

aellwein avatar aellwein commented on August 9, 2024

Thank you 👍

from aiocoap.

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.