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

Not able to make a Thenable Class #63

Closed
shiny opened this issue Apr 19, 2024 · 2 comments
Closed

Not able to make a Thenable Class #63

shiny opened this issue Apr 19, 2024 · 2 comments
Assignees
Labels
Type: Question Needs clarification

Comments

@shiny
Copy link

shiny commented Apr 19, 2024

Package version

@adonisjs/fold@10.0.1

Describe the bug

This is a simple Thenable Class Example

class Database {
    where() {
        return this
    }
    and() {
        return this
    }
    limit() {
        return this
    }
    then(onFulfilled: (result: string) => any) {
        onFulfilled('my example result')
    }
}

What I expect is

const db = await app.container.make(Database)
const result = await db.where().and().limit()
result === 'my example result''

But the result is db === 'my example result', not a instance of Database.
The thenable class is useful for graceful chain methods

Reproduction repo

https://github.com/shiny/reproduce-thenable-class-issue/blob/main/tests/unit/example.spec.ts

@thetutlage
Copy link
Member

That's expected because that's how await works under the hood. It will resolve all the promises.

I am not sure there any simple way to work around this. Lemme know if you have anything in mind.

@thetutlage thetutlage self-assigned this Apr 22, 2024
@thetutlage thetutlage added the Type: Question Needs clarification label Apr 22, 2024
@shiny
Copy link
Author

shiny commented Apr 22, 2024

Oh I get it now, thank you for your patience to help.

@shiny shiny closed this as completed Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Question Needs clarification
Projects
None yet
Development

No branches or pull requests

2 participants