|
1 | 1 | //! relaxed-idb vfs implementation |
| 2 | +//! |
2 | 3 | //! **The `relaxed-idb` feature is required, and it is not recommended to use in a production environment.** |
3 | 4 | //! |
4 | 5 | //! ```rust |
@@ -900,26 +901,27 @@ impl RelaxedIdbUtil { |
900 | 901 |
|
901 | 902 | /// Register `relaxed-idb` vfs and return a utility object which can be used |
902 | 903 | /// to perform basic administration of the file pool |
| 904 | +/// |
| 905 | +/// If the vfs corresponding to `options.vfs_name` has been registered, |
| 906 | +/// only return a utility object. |
903 | 907 | pub async fn install(options: &RelaxedIdbCfg, default_vfs: bool) -> Result<RelaxedIdbUtil> { |
904 | 908 | static REGISTER_GUARD: tokio::sync::Mutex<()> = tokio::sync::Mutex::const_new(()); |
905 | 909 | let _guard = REGISTER_GUARD.lock().await; |
906 | 910 |
|
907 | | - let pool = match registered_vfs(&options.vfs_name) { |
908 | | - Ok(vfs) => unsafe { RelaxedIdbStore::app_data(vfs) }, |
909 | | - Err(RegisterVfsError::VfsNotRegistered) => { |
910 | | - let (tx, rx) = tokio::sync::mpsc::unbounded_channel(); |
911 | | - let pool = RelaxedIdb::new(options, tx).await?; |
912 | | - let vfs = register_vfs::<RelaxedIdbIoMethods, RelaxedIdbVfs>( |
913 | | - &options.vfs_name, |
914 | | - pool, |
915 | | - default_vfs, |
916 | | - )?; |
917 | | - |
918 | | - let app_data = unsafe { RelaxedIdbStore::app_data(vfs) }; |
919 | | - wasm_bindgen_futures::spawn_local(app_data.commit_loop(rx)); |
920 | | - app_data |
921 | | - } |
922 | | - Err(vfs_error) => return Err(RelaxedIdbError::Vfs(vfs_error)), |
| 911 | + let pool = if let Some(vfs) = registered_vfs(&options.vfs_name)? { |
| 912 | + unsafe { RelaxedIdbStore::app_data(vfs) } |
| 913 | + } else { |
| 914 | + let (tx, rx) = tokio::sync::mpsc::unbounded_channel(); |
| 915 | + let pool = RelaxedIdb::new(options, tx).await?; |
| 916 | + let vfs = register_vfs::<RelaxedIdbIoMethods, RelaxedIdbVfs>( |
| 917 | + &options.vfs_name, |
| 918 | + pool, |
| 919 | + default_vfs, |
| 920 | + )?; |
| 921 | + |
| 922 | + let app_data = unsafe { RelaxedIdbStore::app_data(vfs) }; |
| 923 | + wasm_bindgen_futures::spawn_local(app_data.commit_loop(rx)); |
| 924 | + app_data |
923 | 925 | }; |
924 | 926 |
|
925 | 927 | Ok(RelaxedIdbUtil { pool }) |
|
0 commit comments