Comments (13)
- notify.Error
const (
Create = Event(...)
Delete = Event(...)
...
Error = Event(...)
)
notify.Watch("/home/pknap/rottenbodies", ch, notify.Delete, notify.Error)
for ei := range ch {
switch ei.Event() {
case notify.Delete:
println("the bodies are gone")
case notify.Error:
println("they're alive:", ei.Sys().(error))
}
}
notify.Watch("/path", ch)
listensnotify.Error
by default as well- not listening to a
notify.Error
means it's ignored
It's guaranteed that:
- a
notify.Error
is followed by a chan close - when
Event() == notify.Error
, it's safe toerr := ei.Sys().(error)
Plus is minimalistic API. Cons is Error is not an event... oh wait, it is. XD
Other than that I like 1).
from notify.
How about an implicit notify.Error event:
notify.Watch("/home/pknap/rottenbodies", ch, notify.Delete)
for ei := range ch {
switch ei.Event() {
case notify.Delete:
println("the bodies are gone")
case notify.Error:
println("they're alive:", ei.Sys().(error))
}
}
I`ve updated option no.1 and I like it too.
from notify.
It should be possible to say: Watch this and I don't care about the error, just close the chan
. Because receiving notify.Error
and not reading Sys().(error)
gives the same information as !ok
received by the chan close.
from notify.
In the other hand, how long should we keep the ch<-->error pair. Since the user may want to always call notify.Error(ch) on deleted channel?
from notify.
Yup, the problem with 1) is the lifetime of underlying map[chan<- notify]error
. No idea how to deal with that. That's why I would pick 3), as eventually deleting notify.Error
and introducing something else is relatively simple.
from notify.
Ok in this case we send ch <- zjebalosie{err: err} and then close the channel ?
from notify.
If zjebalosie
implements EventInfo
it's cool.
from notify.
👍
from notify.
notify.Error
is implicit, meaning thech
after followingWatch
may receive an error
notify.Watch("/path", ch, notify.Create)
- in order to ignore receiving an error user may want to use
^notify.Error
:
notify.Watch("/path", ch, notify.Create, ^notify.Error)
(obviously this wouldn't work with short event declaration, like: notify.Create | ^notify.Error
, only long one is supported)
from notify.
eg:
notify.Create == Event(0x1) // 0001b
notify.Delete == Event(0x2) // 0010b
notify.Move == Event(0x4) // 0100b
notify.Error == Event(0x8) // 1000b
...
notify.Create | notify.Delete | notify.Move == ^notify.Error
.... => // the only fix?:
notify.Error == notify.Create | notify.Delete | notify.Move
...
Is it possible to implement this logic correctly?
[edit]
Hmm hopefully it is, but notify.Error
needs to reserve 2 bits 👍
from notify.
If it has two bits reserved also your notify.Create | ^notify.Error
will be possible:
notify.Create == Event(0x1) // 00001b
notify.Delete == Event(0x2) // 00010b
notify.Move == Event(0x4) // 00100b
notify.Error == Event(0x8) // 01000b , bit 4th ant 5th are reserved
bit 4th == 0
, bit 5th == 0
=> implicit error
bit 4th == 1
, bit 5th == 0
=> explicit notify.Error was passed as an argument
bit 4th == 0
, bit 5th == 1
=> explicit ^notify.Error was passed
bit 4th == 1
, bit 5th == 1
=> somebody tries to cheat us
[edit]
bit 4th == 1
, bit 5th == 1
=> notify.Error | ^notify.Error => no-op <=> bit 4th == 0
, bit 5th == 0
from notify.
- taken from os/signal
Notify causes package signal to relay incoming signals to c. If no signals are listed, all incoming signals will be relayed to c. Otherwise, just the listed signals will.
thus:
notify.Watch("dupa", ch) == notify.Watch("dupa", ch, notify.Create, notify.Delete, notify.Move, notify.Error, notify.Write) // but not system-dependent events.
;>
from notify.
and if we have the notify.Error
event I would rather not close the channel on error.
- no need to write creepy logic which is responsible for storing errors.
- I can recover the reading loop after error occures (
inotify
/ReadDirectoryChanges
) - os/signal has no such logic
- the code will panic if someone receives nil
EventInfo
from closed channel and invokesei.Event()
from notify.
Related Issues (20)
- Panic in windows on loopevent HOT 3
- build error from mac osx 10.15 fatal error: 'CoreServices/CoreServices.h' file not found HOT 8
- Zero action causing "panic: notify: cannot decode internal mask" HOT 3
- NonrecursiveTree does not watch recreated folders
- Recursive watcher for windows shared drive does not report events in subdirectories HOT 1
- FILE_TRUNC does not exist on Solaris
- Can't cross compile for darwin/arm64 from darwin/amd64 HOT 1
- Still "under active development"? HOT 2
- SIGSEGV when built with 1.17 on macOS HOT 1
- Only listen for folder additions or deletions, but not file additions or deletions ?
- C.FSEventStreamScheduleWithRunLoop(ref, runloop, C.kCFRunLoopDefaultMode) MacOS 13 future remove HOT 4
- This library does not build on macOS ventura (13.0.1) HOT 1
- v0.9.3(4?) release naming HOT 2
- FSEvents are sometimes not notified due to strip() logic following rename
- fatal error: checkptr: converted pointer straddles multiple allocations HOT 2
- inotify event path may be incorrect if wd is not yet updated to its new path
- undefined: stream - Issue with Mac OS M2 HOT 6
- FSEventStreamCreate is not available at ios HOT 5
- "The parameter is incorrect." error when watching files on Windows HOT 1
- Recursive dir watching on Linux seems unreliable
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from notify.