Giter VIP home page Giter VIP logo

synchronized-promise's Issues

It's very slow for me.

This package is cool it makes something possible (in workaround situations) that should not be.. but from my initial tests it's very slow.

Following test case: (node v18.14.0)

const sp = require('synchronized-promise');
const a = async function( x ) { return x + 1; }
const b = function b( x ) { return x + 1; }
const n = 50;

console.time( 'simple sync');
let v = 0;
for( let i = 0; i < n; i++ )
{
	v = b( v );
}
console.timeEnd( 'simple sync');

console.time( 'synchornized promise');
const as = sp( a );
v = 0;
for( let i = 0; i < n; i++ )
{
	v = as( v );
}
console.timeEnd( 'synchornized promise');


console.time( 'classic async');
( async function test( )
{
	v = 0;
	for( let i = 0; i < n; i++ )
	{
		v = await a( v );
	}
	console.timeEnd( 'classic async');
}) ( );

classic async has to be last test, since the main loop would continue straight away.

Result:

$ node src/a.js 
simple sync: 0.044ms
synchornized promise: 5.022s
classic async: 0.136ms

As expected promises are a tad slower than direct calls.. but syncronized promises, is way out there in being extremly slow (the code generator I wanted to use it in, where I have an await edge case turns from being almost instant to .. wait a minute or two).

I'm okay with again some overhead to await/async, but this is a bit too much.

似乎不支持 this?

如果一个异步方法里面调用了 this,似乎是不支持的,有办法支持吗?

例子:

class A {
  constructor() { this.x = 1; }
  async getX() { return this.x; }
}
const a = new A();
sp(a.getX)();
// 会报错  Cannot read property 'x' of undefined

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.