Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Socket callbacks require Sync auto-trait #53

Closed
fussybeaver opened this issue Nov 1, 2021 · 4 comments
Closed

Socket callbacks require Sync auto-trait #53

fussybeaver opened this issue Nov 1, 2021 · 4 comments
Labels
bug Something isn't working

Comments

@fussybeaver
Copy link
Contributor

Thanks for adding socket support recently. I gave it a try, though quite quickly ran into an issue - the callbacks on SlackSocketModeListenerCallbacks require the Sync auto-trait, which is not implemented on hyper's response Futures. So, you cannot simply use the client in a callback function to do arbitrary API requests:

async fn slack_command_events_fn(
    event: SlackCommandEvent,
    client: Arc<SlackHyperClient>,
    _states: Arc<RwLock<SlackClientEventsUserStateStorage>>,
) -> Result<SlackCommandEventResponse, Box<dyn std::error::Error + Send + Sync>> {
    let session = client.open_session(&...);
    let res = session
        .conversations_create(&SlackApiConversationsCreateRequest {
            name: "my_fancy_new_channel",
            is_private: Some(false),
            user_ds: None,
        })
        .await?;
    }
    // ...
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
    // ...    
    let socket_mode_callbacks = SlackSocketModeListenerCallbacks::new()
        .with_command_events(slack_command_events_fn);
    // ...
}

error[E0277]: `dyn Future<Output = Result<slack_morphism::api::SlackApiConversationsCreateResponse, Box<dyn std::error::Error + Send + Sync>>> + Send` cannot be shared between threads safely
   --> src/main.rs:140:10
    |
140 |         .with_command_events(slack_command_events_fn)
    |          ^^^^^^^^^^^^^^^^^^^ `dyn Future<Output = Result<slack_morphism::api::SlackApiConversationsCreateResponse, Box<dyn std::error::Error + Send + Sync>>> + Send` cannot be shared between threads safely
    |
    = help: the trait `Sync` is not implemented for `dyn Future<Output = Result<slack_morphism::api::SlackApiConversationsCreateResponse, Box<dyn std::error::Error + Send + Sync>>> + Send`

Let me know if I'm doing something wrong here...

@abdolence
Copy link
Owner

Interesting, thanks for testing it. It is a new thing, so might have some issues like this. Let me check your example.

@abdolence
Copy link
Owner

I think I fixed it with:
99749bb

And to make sure it won't happen again modified examples to have at least one call there.

@abdolence
Copy link
Owner

Fixed in v0.12.0. Please let me know if it works for you as well. The Sync part was copied from another place, and it wasn't required.

@fussybeaver
Copy link
Contributor Author

Thanks for the quick fix!

@abdolence abdolence added the bug Something isn't working label Nov 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants