Code Monkey home page Code Monkey logo

sleep-promise's People

Contributors

brummelte avatar kachkaev avatar lledey avatar renovate-bot avatar renovate[bot] avatar satazor avatar semantic-release-bot avatar tommyxu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

sleep-promise's Issues

v 4.1 not working in a TypeScript project

Hi again @brummelte and thanks for your efforts to move the project to the next level!

I'm writing to report that sleep-promise v4.1 does not work in a TypeScript project. This is because Node still imports a js file rather than an mjs, but that file does not have a default export. Now the library is not usable because when I type import * as sleep from "sleep-promise", I get a TypeScript compiler error, expectedly coming from index.d.ts, but when I try import sleep as "sleep-promise" and get cool TS hints, this exception shows up:

TypeError: sleep_promise_1.default is not a function

I guess you'll need to export sleep function twice to make bundle.js compatible with both require and import:

module.exports = sleep;
module.exports.default = module.exports;

This is what chalk does at least, but they are implementing both flavours of exports manually. Given that your source is in es6 now, perhaps, there is some rollup option that would do the trick?

Rolling back to v2 for now πŸ˜‰

A release without core-js

An unnecessary dependency on core-js was removed in #27 in October. However, the latest published release (9.0.0) still includes it. It’d be great if you could release 9.0.1 at some point, which would not includecore-js. This may resolve certain issues related to dependency hoisting and resolution. Cheers!

Does not work when using sinon.useFakeTimers()

sinon is a popular stubbing framework for JavaScript unit tests. sinon.useFakeTimers() replaces the global setTimeout() method with its own, allowing unit tests to instantly move time forward instead of waiting for time to pass.

Because this project calls the global setTimeout() method, it will not work if sinon.useFakeTimers() is called.

A simple solution would be to store the global setTimeout() method before sinon replaces it:

sleep-promise/lib/index.js

const setTimeout = global.setTimeout;

// sleep() implementation...

someProject/test.js

const sleep = require('sleep-promise');
const clock = sinon.useFakeTimers();

// Unit test code...

If you're ok with this from a design perspective, I'd be happy to open a PR.

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/rebase.yml
  • actions/checkout v4
  • cirrus-actions/rebase 1.3.1
.github/workflows/release.yml
  • actions/checkout v4
  • actions/setup-node v4
npm
.yarn/sdks/eslint/package.json
.yarn/sdks/typescript/package.json
package.json
  • @babel/cli ^7.24.7
  • @babel/core ^7.24.7
  • @babel/plugin-transform-runtime ^7.24.7
  • @babel/preset-env ^7.24.7
  • @brummelte/eslint-config ^9.2.29
  • @semantic-release/changelog ^6.0.3
  • @semantic-release/commit-analyzer ^12.0.0
  • @semantic-release/git ^10.0.1
  • @semantic-release/github ^10.0.6
  • @semantic-release/npm ^12.0.1
  • @semantic-release/release-notes-generator ^13.0.0
  • babel-jest ^29.7.0
  • copyfiles ^2.4.1
  • coveralls ^3.1.1
  • eslint ^8.57.0
  • jest ^29.7.0
  • jest-junit ^16.0.0
  • rimraf ^5.0.7
  • rollup ^2.79.1
  • rollup-plugin-babel ^4.4.0
  • rollup-plugin-node-resolve ^5.2.0
  • rollup-plugin-terser ^7.0.2
  • semantic-release ^23.1.1
  • typescript ^5.4.5

  • Check this box to trigger a request for Renovate to run again on this repository

Provides a helper to delay a promise chain

I imagine a method to delay a promise chain would be extremely useful.

Something to allow:

Promise.resolve("hello world")
    .then(sleep(5000))
    .then(x => x.toUpperCase())
    .then(x => console.log(x))

this can be useful to control an animation or display a notification

sendEmail("[email protected]")
    .then(showNotification)
    .then(sleep(200))
    .then(id => hideNotification(id))

what do you think?

Feature request: cancel promise

I'm using this library for handling timeout stuffs or something else like:

await Promise.all([
  triggerPromise(),
  Promise.race([
    eventPromise.then(...), // event might be invoked or not
    sleep(1000).then(() => Promise.reject('timeout exceeded of 1000ms while ...')), // timeout
  ]),
]);

(feature request)
In the case above all things are good, however I have faced a situation where the sleep promise should be cancelled to continue, as like:

const timeout = sleep(1000).then(() => Promise.reject(...));
await Promise.all([
  triggerPromise(),
  Promise.race([
    eventPromise.then(() => {
      timeout.cancel(); // here
      return operationPromiseThatTakesMoreThanTimeout();
    }),
    timeout,
  ]);
]);

(current solution)
Anyway, this goal can be reached by writing code like as follows:

const timeout = sleep(1000).then(() => Promise.reject(...));
await Promise.all([
  triggerPromise(),
  new Promise((resolve, reject) => {
    let handled = false;

    eventPromise.then(() => {
      handled = true;
      operationPromiseThatTakesMoreThanTimeout().then(resolve);
    });

    sleep(1000).then(() => { // or `setTimeout`
      if (handled) {
        return;
      }
      reject(...);
    });
  }),
]);

(or similar)

but you may know this is bad idea/style, just because if sleep-promise supports promise cancellation for the case like this.

TypeScript typings

It'd be great if the library provided TypeScript typings! Otherwise, this warning is shown next to import * as sleep from "sleep-promise";:

Could not find a declaration file for module 'sleep-promise'.
'/path/to/project/node_modules/sleep-promise/lib/index.js' implicitly has an 'any' type.
Try `npm install @types/sleep-promise` if it exists or add a new declaration
(.d.ts) file containing `declare module 'sleep-promise';`

I can submit a PR if this idea gets approved.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.