What are the implications of "awaiting" for a synchronous function/method

Viewed 22

Let's say I have the following TypeScript implementation:

interface SomeInterface {
  bar(): Promise<string> | string
}

class SynchronousImplementation implements SomeInterface {
  bar(): string {
    return 'Hello Sync!'
  }
}

class AsynchronousImplementation implements SomeInterface {
  bar(): Promise<string> {
    return Promise.resolve('Hello Async!')
  }
}

class ConcreteClass {
  constructor(
    private readonly implementation: SomeInterface
  ) {}

  foo() {
    return this.implementation.bar()
  }
}

(async () => {
  const asynchronousImplementationInstance = new AsynchronousImplementation()
  const synchronousImplementationInstance = new SynchronousImplementation()
  const someConcreteClassInstance = new ConcreteClass(asynchronousImplementationInstance)
  const anotherConcreteClassInstance = new ConcreteClass(synchronousImplementationInstance)

  const someResult = await someConcreteClassInstance.foo()
  const anotherResult = await anotherConcreteClassInstance.foo()
})()

Is there any undesired implicit consequences of "awaiting" for a function that in practice is synchronous, such as await anotherConcreteClassInstance.foo(), in terms of performance, memory usage, event loop or anything related to runtime?

0 Answers
Related