- Get Started
- Product
- Resources
- Tools & SDKs
- Framework
- Reference
Menu
- Get Started
- Product
- Resources
- Tools & SDKs
- Framework
- Reference
4.3.5. Service Constraints
This chapter lists constraints to keep in mind when creating a service.
Use Async Methods#
Medusa wraps service method executions to inject useful context or transactions. However, since Medusa can't detect whether the method is asynchronous, it always executes methods in the wrapper with the await
keyword.
For example, if you have a synchronous getMessage
method, and you use it in other resources like workflows, Medusa executes it as an async method:
So, make sure your service's methods are always async to avoid unexpected errors or behavior.
1import { MedusaService } from "@medusajs/framework/utils"2import MyCustom from "./models/my-custom"3 4class HelloModuleService extends MedusaService({5 MyCustom,6}){7 // Don't8 getMessage(): string {9 return "Hello, World!"10 }11 12 // Do13 async getMessage(): Promise<string> {14 return "Hello, World!"15 }16}17 18export default HelloModuleService
Was this chapter helpful?