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

异步是什么? #46

Open
1 task
zhouzhongyuan opened this issue Apr 8, 2017 · 4 comments
Open
1 task

异步是什么? #46

zhouzhongyuan opened this issue Apr 8, 2017 · 4 comments

Comments

@zhouzhongyuan
Copy link
Owner

zhouzhongyuan commented Apr 8, 2017

@zhouzhongyuan zhouzhongyuan changed the title 异步会什么? 异步是什么? Apr 8, 2017
@zhouzhongyuan
Copy link
Owner Author

竞态条件(race condition):函数顺序的不确定性。

foo与bar相互竞争,看谁先运行。因为无法可靠预测a和b的最终结果,所以才叫做race condition.

var a = 1;
var b = 2;

function foo() {
	a++;
	b = b * a;
	a = b + 3;
}

function bar() {
	b--;
	a = 8 + b;
	b = a * 2;
}

// ajax(..) is some arbitrary Ajax function given by a library
ajax( "http://some.url.1", foo );
ajax( "http://some.url.2", bar );

@zhouzhongyuan
Copy link
Owner Author

zhouzhongyuan commented Apr 8, 2017

  • 原子性是什么? run-to-completion是什么? 两者什么关系?

foo和bar中的代码具有原子性。
有些函数不具有run-to-completion的特性,那么最终结果就会有很多。ES6引入了这个东西。
//TODO
什么东西?
答:生成器。generator函数。

@zhouzhongyuan
Copy link
Owner Author

  • generator为什么需要iterator来控制?

@zhouzhongyuan
Copy link
Owner Author

zhouzhongyuan commented Aug 28, 2018

20180827 14:07

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

No branches or pull requests

1 participant