Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Async middleware abstraction powered by AFIT and RPITIT.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
NotificationsYou must be signed in to change notification settings

cloudwego/motore

Motore

Crates.ioDocumentationLicenseBuild Status

Motore is an async middleware abstraction powered by AFIT and RPITIT.

Around Motore, we build modular and reusable components for building robust networking clients and servers.

Motore is greatly inspired byTower.

Overview

Motore uses AFIT and RPITIT to reduce the mental burden of writing asynchronous code, especially to avoid the overhead ofBox to make people less anxious.

The core abstraciton of Motore is theService trait:

pubtraitService<Cx,Request>{/// Responses given by the service.typeResponse;/// Errors produced by the service.typeError;/// Process the request and return the response asynchronously.asyncfncall(&self,cx:&mutCx,req:Request) ->Result<Self::Response,Self::Error>;}

Getting Started

Combing AFIT and RPITIT together, we can write asynchronous code in a very concise and readable way.

pubstructTimeout<S>{inner:S,duration:Duration,}impl<Cx,Req,S>Service<Cx,Req>forTimeout<S>whereReq:'static +Send,S:Service<Cx,Req> +'static +Send +Sync,Cx:'static +Send,S::Error:Send +Sync +Into<BoxError>,{typeResponse =S::Response;typeError =BoxError;asyncfncall(&self,cx:&mutCx,req:Req) ->Result<Self::Response,Self::Error>{let sleep = tokio::time::sleep(self.duration);        tokio::select!{            r =self.inner.call(cx, req) =>{                r.map_err(Into::into)},            _ = sleep =>Err(std::io::Error::new(std::io::ErrorKind::TimedOut,"service time out").into()),}}}

We also provided the#[motore::service] macro to make writing aSerivce more async-native:

use motore::service;pubstructS<I>{inner:I,}#[service]impl<Cx,Req,I>Service<Cx,Req>forS<I>whereReq:Send +'static,I:Service<Cx,Req> +Send +'static +Sync,Cx:Send +'static,{asyncfncall(&self,cx:&mutCx,req:Req) ->Result<I::Response,I::Error>{self.inner.call(cx, req).await}}

FAQ

Where's thepoll_ready(a.k.a. backpressure)?

https://www.cloudwego.io/docs/volo/faq/#where-did-poll_ready-backpressure-go

License

Motore is dual-licensed under the MIT license and the Apache License (Version 2.0).

SeeLICENSE-MIT andLICENSE-APACHE for details.

Credits

We have used some third party components, and we thank them for their work.

For the full list, you may refer to theCREDITS.md file.

Community

About

Async middleware abstraction powered by AFIT and RPITIT.

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Code of conduct

Security policy

Stars

Watchers

Forks

Languages


[8]ページ先頭

©2009-2025 Movatter.jp