Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@aikar/dpromise
Advanced tools
Deferred Promises. Create a promise that allows deferring completion of the promise for more flexible control.
Deferred Promises. Create a promise that allows deferring completion of the promise for more flexible control.
import {deferPromise} from "@aikar/dpromise";
// or
const {deferPromise} = require("@aikar/dpromise");
const promise = deferPromise();
promise.resolve();
promise.reject(new Error());
Standard promise creation implies that the creator of the promise will begin the process of how to fulfill the promise.
But what if that is not what you want? What if you want something else to fulfill the promise?
Deferred promises accomplish this by decoupling Promise creation from Promise fulfillment.
"Isn't this an anti pattern?" You may of heard that Promise.defer() and the like in Bluebird is an "anti-pattern", but rest assured, it is not.
Just because an experienced person says something, does not make it true. Anyone declaring that this is an anti pattern is expressing an OPINION.
And here I am expressing my opinion that they are wrong and used very poor reasoning for declaring such a statement.
Both the reasons stated at Bluebird are invalid.
If we are going to accuse a specific pattern to be an anti pattern because some developer used it when a better solution was available, then we might as well call the entire language an anti pattern.
Let's also mention that this pattern is part of the core system for Java 8+ Promise/Future support. To say this is an anti pattern, would be saying the same for the entire CompletableFuture system in Java.
This is a tool. There are many tools in your toolbox. Misusing a tool is not the tools fault.
Yes, they all return an object wrapper requiring you to do await result.promise;
This library returns an actual extended Promise object.
Override the Promise export this module exports (Not recommended)
require("@aikar/dpromise").Promise = require("bluebird");
dpromise (c) Daniel Ennis (Aikar) 2019-present. dpromise is licensed MIT. See LICENSE
FAQs
Deferred Promises. Create a promise that allows deferring completion of the promise for more flexible control.
We found that @aikar/dpromise demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.