async fn add_account(
        &self,
        account_handler: Arc<AccountHandlerConnection>,
        account_id: LocalAccountId,
    ) -> Result<(), AccountManagerError> {
        let mut ids_to_handlers_lock = await!(self.ids_to_handlers.lock());
        if ids_to_handlers_lock.get(&account_id).is_some() {
            // IDs are 64 bit integers that are meant to be random. Its very unlikely we'll create
            // the same one twice but not impossible.
            // TODO(dnordstrom): Avoid collision higher up the call chain.
            return Err(AccountManagerError::new(Status::UnknownError)
                .with_cause(format_err!("Duplicate ID {:?} creating new account", &account_id)));
        }
        let mut account_ids: Vec<StoredAccountMetadata> =
            ids_to_handlers_lock.keys().map(|id| StoredAccountMetadata::new(id.clone())).collect();
        account_ids.push(StoredAccountMetadata::new(account_id.clone()));
        if let Err(err) = StoredAccountList::new(account_ids).save(&self.data_dir) {
            // TODO(dnordstrom): When AccountHandler uses persistent storage, clean up its state.
            return Err(err);
        }
        ids_to_handlers_lock.insert(account_id.clone(), Some(account_handler));
        let event = AccountEvent::AccountAdded(account_id.clone());
        await!(self.event_emitter.publish(&event));
        Ok(())
    }
// Add the account to the AccountManager, including persistent state.
Add the account to the AccountManager, including persistent state.
Add the account to the AccountManager including persistent state .
async fn add_account(
        &self,
        account_handler: Arc<AccountHandlerConnection>,
        account_id: LocalAccountId,
    ) -> Result<(), AccountManagerError> {
        let mut ids_to_handlers_lock = await!(self.ids_to_handlers.lock());
        if ids_to_handlers_lock.get(&account_id).is_some() {
            // IDs are 64 bit integers that are meant to be random. Its very unlikely we'll create
            // the same one twice but not impossible.
            // TODO(dnordstrom): Avoid collision higher up the call chain.
            return Err(AccountManagerError::new(Status::UnknownError)
                .with_cause(format_err!("Duplicate ID {:?} creating new account", &account_id)));
        }
        let mut account_ids: Vec<StoredAccountMetadata> =
            ids_to_handlers_lock.keys().map(|id| StoredAccountMetadata::new(id.clone())).collect();
        account_ids.push(StoredAccountMetadata::new(account_id.clone()));
        if let Err(err) = StoredAccountList::new(account_ids).save(&self.data_dir) {
            // TODO(dnordstrom): When AccountHandler uses persistent storage, clean up its state.
            return Err(err);
        }
        ids_to_handlers_lock.insert(account_id.clone(), Some(account_handler));
        let event = AccountEvent::AccountAdded(account_id.clone());
        await!(self.event_emitter.publish(&event));
        Ok(())
    }
async fn add_account ( & self , account_handler : Arc < AccountHandlerConnection > , account_id : LocalAccountId , ) -> Result < ( ) , AccountManagerError > { let mut ids_to_handlers_lock = await ! ( self ids_to_handlers lock ( ) ) ; if ids_to_handlers_lock . get ( & account_id ) . is_some ( ) { // IDs are 64 bit integers that are meant to be random. Its very unlikely we'll create // the same one twice but not impossible. // TODO(dnordstrom): Avoid collision higher up the call chain. return Err ( AccountManagerError :: new ( Status :: UnknownError ) . with_cause ( format_err ! ( " " account_id ) ) ) ; } let mut account_ids : Vec < StoredAccountMetadata > = ids_to_handlers_lock . keys ( ) . map ( | id | StoredAccountMetadata :: new ( id . clone ( ) ) ) . collect ( ) ; account_ids . push ( StoredAccountMetadata :: new ( account_id . clone ( ) ) ) ; if let Err ( err ) = StoredAccountList :: new ( account_ids ) . save ( & self . data_dir ) { // TODO(dnordstrom): When AccountHandler uses persistent storage, clean up its state. return Err ( err ) ; } ids_to_handlers_lock . insert ( account_id . clone ( ) , Some ( account_handler ) ) ; let event = AccountEvent :: AccountAdded ( account_id . clone ( ) ) ; await ! ( self event_emitter publish ( event ) ) ; Ok ( ( ) ) }
Add the account to the AccountManager, including persistent state.
Add the account to the AccountManager including persistent state .
&self
account_handler
Arc<AccountHandlerConnection>
account_id
LocalAccountId
&self
account_handler
Arc<AccountHandlerConnection>
account_id
LocalAccountId