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

feat(ext/timers): add refTimer, unrefTimer API (alt) #12953

Merged
merged 3 commits into from
Dec 9, 2021

Conversation

kt3k
Copy link
Member

@kt3k kt3k commented Dec 1, 2021

depends on #12862 (alternative to #12942)

This PR adds Deno.refTimer and Deno.unrefTimer APIs in the unstable namespace.


closes #6141

Copy link
Contributor

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a rebase but #12862 was merged earlier today and this PR otherwise LGTM.


// Step 4 in "run steps after a timeout".
MapPrototypeSet(activeTimers, id, cancelRid);
timerInfo = { cancelRid, isRef: true };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-       timerInfo = { cancelRid, isRef: true };
+       timerInfo = { cancelRid, isRef: true, promiseId: -1 };

Keeps the object monomorphic.

@@ -255,6 +263,24 @@
clearTimeout(id);
}

function refTimer(id = 0) {
const timerInfo = MapPrototypeGet(activeTimers, id);
if (timerInfo.isRef) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (timerInfo === undefined || timerInfo.isRef) { (ditto on line 277)

The id = 0 default argument is kind of weird/footgun-y, I'd remove that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (timerInfo === undefined || timerInfo.isRef) { (ditto on line 277)

Oops. Thanks!

The id = 0 default argument is kind of weird/footgun-y, I'd remove that.

I blindly followed the pattern used in clearTimeout/clearInterval, but I agree with your point

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM too! Nice work @kt3k

@kt3k kt3k merged commit 69ad5f0 into denoland:main Dec 9, 2021
@kt3k kt3k deleted the unref-timer-2 branch December 9, 2021 08:01
@jcs224
Copy link

jcs224 commented May 5, 2022

Is there any timeline this might go from unstable to stable? I think this might be the only thing preventing me from being able to push jobs from Deno Deploy to BullMQ

error: TypeError: Deno.unrefTimer is not a function
at Timeout.unref (https://deno.land/std@0.137.0/node/internal/timers.mjs:42:10)
at setUnrefTimeout (https://deno.land/std@0.137.0/node/timers.ts:32:36)
at Socket.setStreamTimeout [as setTimeout] (https://deno.land/std@0.137.0/node/internal/stream_base_commons.ts:339:22)
...
private output
...
at processTicksAndRejections (https://deno.land/std@0.137.0/node/_next_tick.ts:80:12)

@kt3k
Copy link
Member Author

kt3k commented May 5, 2022

@jcs224 How do you try to use Bull MQ in Deploy? Is it via esm.sh? Do you import https://esm.sh/bullmq?

@jcs224
Copy link

jcs224 commented May 5, 2022

I've been using the Node require polyfill, this works fine with the --unstable flag:

import { createRequire } from "https://deno.land/std@0.138.0/node/module.ts";
const require = createRequire(import.meta.url);

const { Queue } = require('bullmq')

const myQueue = new Queue('foo')

However, when I try this:

import { Queue } from 'https://esm.sh/bullmq'

const myQueue = new Queue('foo')

I get a weird lodash error

error: Uncaught SyntaxError: The requested module '/v78/lodash@4.17.21/deno/lodash.js' does not provide an export named 'get' at https://cdn.esm.sh/v78/bullmq@1.81.4/deno/bullmq.js:7:20803

Also, I've been doing this all with the CLI, not deploy. I know that Deploy only uses stable API so I didn't even bother to try. The node require polyfill should work in Deploy though, right? I should have probably checked that...

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.

Feature request: Support async unref for timers
4 participants