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

[NEW] Add a bridge to the ITimers interface #439

Open
wants to merge 1 commit into
base: alpha
Choose a base branch
from

Conversation

kirillk77
Copy link

What? ⛵

This pull request contains an implementation of the bridge to the ITimers interface.

Why? 🤔

The ITimers interface is very useful to implement custom protocols, circuit breakers, throttlers, complex actions and so on.

@d-gubert
Copy link
Member

Hey @cybem! Thank you for taking the time to make this PR :)

One thing that's not clear to me based on the implementation is how you intend to use this new bridge in the app. Can you provide an example?

I'm guessing it might have something to do with functions like setTimeout and setInterval, is that the case?

@kirillk77
Copy link
Author

Hey @cybem! Thank you for taking the time to make this PR :)

One thing that's not clear to me based on the implementation is how you intend to use this new bridge in the app. Can you provide an example?

Hello, Douglas @d-gubert!

We use it in that manner:

   private delay(ms: number) {
        const setTimeout = this.timers.call('setTimeout');
        return new Promise((resolve) => setTimeout(resolve, ms));
    }

But we can adapt source code of our app to more elegant solution of the bridge.

Thank you for your feedback!

@d-gubert
Copy link
Member

d-gubert commented Aug 31, 2021

But we can adapt source code of our app to more elegant solution of the bridge.

We're considering allowing access to the functions directly via global scope, much like how you'd have in a pure NodeJS environment. I think it would solve your use case as well, right?

Usually we create bridges for apps to access resources that are directly related to Rocket.Chat, such as data entities like messages and rooms; or features that are tightly coupled to the database, like the persistence layer or scheduler.

These functions from the timers module are provided globally by NodeJS, so we could pass them directly to the app as well.

What do you think?

@kirillk77
Copy link
Author

What do you think?

Hello Douglas @d-gubert,

Yes, sure. It would be nice.

Thank you!

@d-gubert
Copy link
Member

d-gubert commented Oct 7, 2021

I'll be closing this PR as the latest Apps-Engine has those functions available globally. Thanks for contributing the idea :)

@d-gubert d-gubert closed this Oct 7, 2021
@ankar84
Copy link

ankar84 commented Aug 19, 2022

Hello, @d-gubert
As you discussed with @cybem timers module was globally available at late 2021. But now looks like that module not available again.
We see that timers module is imported in Apps-Engine here

import * as timers from 'timers';

But here https://github.com/RocketChat/Rocket.Chat.Apps-engine/blob/eaec68e8179255d81364c88ab68cacbd3f120c87/src/server/compiler/modules/index.ts it not used!
So, looks like a regression critical for us.
Can you check that?
Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants