bakwc / PySyncObj

A library for replicating your python class between multiple servers, based on raft protocol
MIT License
706 stars 113 forks source link

Feature: Add support for update callback #156

Closed mcassaniti closed 2 years ago

mcassaniti commented 2 years ago

When a replicated object is updated and that update is committed, it would be useful to be able to run a callback when the update occurs. For example:

If this is already implemented then I apologise for asking, but it wasn't clear from the documentation.

bakwc commented 2 years ago

There is an automatically added callback argument to all functions marked with replicated decorator. See the docs. Also when you call them with sync=true arguments - they will wait commit automatically. You can instead call them with callback=yourFunc and you will receive a callback as soon as operation committed.

mcassaniti commented 2 years ago

OK, excellent :smile: Is there any documentation on what gets passed to the result argument of the callback function?

bakwc commented 2 years ago

It gets two arguments. First one is what your function returns (None if nothing). And the second one - fail reason enum.

mcassaniti commented 2 years ago

I took me a while to understand this even though the documentation does match what is supposed to happen. Thanks for the feedback. I've only just been able to take another look at pysyncobj after all this time.