Re: [sensors] Add solution for one-shot readings

So, I might be missing something here but would it be wrong to have a 
sensor being active when it has event listeners and deactivated when 
it doesn't? The difference between listening continuously and asking 
just for one value:

```js
let sensor = new GenericSensor();
// listen
sensor.on('whatever', val => console.log(val));
// just get one
sensor.once('whatever', val => console.log(val));
```

As for caching, the sensor instance can expose a cache event emitter. 
It's a simple (generic) interface that fires the appropriate event 
whenever its cache is set. The difference with the sensor is that it 
remembers the last event for every event type, such that when you 
register a listener you always get the latest value (but if there is 
none it will wait for one to happen).

```js
// gets the latest read value
sensor.cache.once('whatever', val => console.log(val))l
```


-- 
GitHub Notification of comment by darobin
Please view or discuss this issue at 
https://github.com/w3c/sensors/issues/88#issuecomment-193003582 using 
your GitHub account

Received on Sunday, 6 March 2016 21:53:49 UTC