nartc / mapper

🔥 An Object-Object AutoMapper for TypeScript 🔥
https://automapperts.netlify.app/
MIT License
985 stars 87 forks source link

feat(core): Add async mapping support with Promises #617

Open koenigstag opened 7 months ago

koenigstag commented 7 months ago

Description

As a developer, I want my async mappings to work, so I've added promise support.

Proposed Changes

Implement a new boolean parameter isAsync to indicate a request for async operations.

Add conditional return of Promise which does async mapping operations inside.

Add type safety for return value with typescript conditional types.

Checklist

sonarcloud[bot] commented 6 months ago

Quality Gate Passed Quality Gate passed

Issues
1 New issue
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

koenigstag commented 6 months ago

Quoting the fake-async docs:

Real async support can be achieved by some Isomorphic Worker that would execute the map operations on the Worker thread

Can someone please explain - why do we need a Node.js Worker thread instead of Promise which are more common?

vellotis commented 3 months ago

Quoting the fake-async docs:

Real async support can be achieved by some Isomorphic Worker that would execute the map operations on the Worker thread

Can someone please explain - why do we need a Node.js Worker thread instead of Promise which are more common?

Hi @koenigstag. Great work for supporting the async/Promised approach!

My opinion is that the fake-async doesn't solve the problem. Long-living non-blocking IO operations may take a lot more time than the fake-async operation that is pushed to the (FIFO) event loop.

Your implementation is the appropriate solution, not the suggested fake-async one.