mirror of
https://github.com/loro-dev/loro.git
synced 2025-02-02 11:06:14 +00:00
Allow commit with custom timestamp (#105)
This commit is contained in:
parent
b22bd98f6b
commit
a661b776c4
1 changed files with 10 additions and 2 deletions
|
@ -12,7 +12,7 @@ use rle::{HasLength, RleVec};
|
|||
use smallvec::smallvec;
|
||||
|
||||
use crate::{
|
||||
change::{get_sys_timestamp, Change, Lamport},
|
||||
change::{get_sys_timestamp, Change, Lamport, Timestamp},
|
||||
container::{
|
||||
idx::ContainerIdx, list::list_op::InnerListOp, text::text_content::SliceRanges,
|
||||
IntoContainerId,
|
||||
|
@ -51,6 +51,7 @@ pub struct Transaction {
|
|||
pub(super) arena: SharedArena,
|
||||
finished: bool,
|
||||
on_commit: Option<OnCommitFn>,
|
||||
timestamp: Option<Timestamp>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, EnumAsInner)]
|
||||
|
@ -97,6 +98,7 @@ impl Transaction {
|
|||
local_ops: RleVec::new(),
|
||||
finished: false,
|
||||
on_commit: None,
|
||||
timestamp: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,6 +110,10 @@ impl Transaction {
|
|||
self._commit()
|
||||
}
|
||||
|
||||
pub fn set_timestamp(&mut self, time: Timestamp) {
|
||||
self.timestamp = Some(time);
|
||||
}
|
||||
|
||||
pub fn set_on_commit(&mut self, f: OnCommitFn) {
|
||||
self.on_commit = Some(f);
|
||||
}
|
||||
|
@ -147,7 +153,9 @@ impl Transaction {
|
|||
ops,
|
||||
deps,
|
||||
id: ID::new(self.peer, self.start_counter),
|
||||
timestamp: oplog.latest_timestamp.max(get_sys_timestamp()),
|
||||
timestamp: oplog
|
||||
.latest_timestamp
|
||||
.max(self.timestamp.unwrap_or_else(get_sys_timestamp)),
|
||||
};
|
||||
|
||||
let diff = if state.is_recording() {
|
||||
|
|
Loading…
Reference in a new issue