mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-08 13:42:39 +00:00
working_copy: add Send supertrait
If WorkingCopy: Send, then Workspace is Send, which is useful for long-running servers. All existing impls are Send already, so this is just a marker.
This commit is contained in:
parent
5eea88d26a
commit
aaa5d6bc4f
2 changed files with 18 additions and 1 deletions
|
@ -32,7 +32,7 @@ use crate::settings::HumanByteSize;
|
||||||
use crate::store::Store;
|
use crate::store::Store;
|
||||||
|
|
||||||
/// The trait all working-copy implementations must implement.
|
/// The trait all working-copy implementations must implement.
|
||||||
pub trait WorkingCopy {
|
pub trait WorkingCopy: Send {
|
||||||
/// Should return `self`. For down-casting purposes.
|
/// Should return `self`. For down-casting purposes.
|
||||||
fn as_any(&self) -> &dyn Any;
|
fn as_any(&self) -> &dyn Any;
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
use std::thread;
|
||||||
|
|
||||||
use assert_matches::assert_matches;
|
use assert_matches::assert_matches;
|
||||||
use jj_lib::op_store::WorkspaceId;
|
use jj_lib::op_store::WorkspaceId;
|
||||||
use jj_lib::repo::Repo;
|
use jj_lib::repo::Repo;
|
||||||
|
@ -84,3 +86,18 @@ fn test_init_additional_workspace() {
|
||||||
);
|
);
|
||||||
assert_eq!(same_workspace.workspace_root(), ws2.workspace_root());
|
assert_eq!(same_workspace.workspace_root(), ws2.workspace_root());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Test cross-thread access to a workspace, which requires it to be Send
|
||||||
|
#[test]
|
||||||
|
fn test_sendable() {
|
||||||
|
let settings = testutils::user_settings();
|
||||||
|
let test_workspace = TestWorkspace::init(&settings);
|
||||||
|
let root = test_workspace.workspace.workspace_root().clone();
|
||||||
|
|
||||||
|
thread::spawn(move || {
|
||||||
|
let shared_workspace = test_workspace.workspace;
|
||||||
|
assert_eq!(shared_workspace.workspace_root(), &root);
|
||||||
|
})
|
||||||
|
.join()
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue