Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Wait till async functions end and forces a synchron process without blocking
Wrapping an async function into a synchron function call without blocking.
npm install synchron --save
Create a new instance of Synchro and use the methods return
and throw
. The wait
method will wait until
return
or throw
was called.
const { Synchron } = require('synchron');
var asyncTimeout = new Synchron();
setTimeout(function(){
// do something
console.log('inside setTimeout');
// and than call done
asyncTimeout.done();
}, 500);
// non-blocking wait until done was called
asyncTimeout.wait();
console.log('back in main');
// output:
// -------
// inside setTimeout
// back in main
Create a new instance and pass a function to wrap the asnyc call into a synchron function.
The warpped function will run in the context of Synchron
, so you can use this.return
and/or this.throw
.
If you like to exit the async function without returning a result just call this.return()
without a parameter or call this.done()
.
const { Synchron } = require('synchron');
var readFileSync = new Synchron(function(filename) {
var fs = require('fs');
fs.readFile(filename, 'utf8', (err, data) => {
if (err) {
this.throw(err);
} else {
this.return(data);
}
});
});
try {
// here is the synchron function call
var data = readFileSync('./testfile.txt');
console.log(data);
} catch (err){
// if an error occours the function will throw it and you can catch it
console.log(err); // maybe an error like: "ENOENT: no such file or directory, open './testfile.txt'"
}
FAQs
Wait till async functions end and forces a synchron process without blocking
The npm package synchron receives a total of 1 weekly downloads. As such, synchron popularity was classified as not popular.
We found that synchron 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.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.