Tag: 比赛条件

用knex迁移保证所有的比赛条件

有人告诉我,Promise.all可以解决诺言的顺序是没有保证的。 但是,我并没有看到它不能从Promise.all原生文档中sorting。 因此,以下knex迁移方法应该不起作用,因为messages具有对用户表的引用。 然而,我从来没有遇到过一次这样的情况,在几次迁徙中,出现了种族差错的情况。 意思是,好像Promise,所有的都是按照索引位置来解决的。 所以,我的问题是:下面的代码片段容易出现竞争状态吗? return Promise.all([ knex.schema.createTable('users', function(table) { table.increments().primary(); … }), knex.schema.createTable('messages', function(table) { table.increments().primary(); table.bigInteger('user_id').unsigned().index() .references('id').inTable('users'); }), 这是更好的方法吗? return Promise.all([ knex.schema.createTable('users', function(table) { table.increments().primary(); … }), ]).then(function() { return Promise.all([ knex.schema.createTable('messages', function(table) { table.increments().primary(); table.bigInteger('user_id').unsigned().index() .references('id').inTable('users'); }), }); })

MEAN JS DB竞赛条件

我已经根据下面的反馈更新了这个问题 如果两个用户都做了一个HTTP请求,那么是否有可能在MEAN堆栈应用程序中产生争用条件:读取logging,根据业务逻辑对logging进行一些更改,然后写回数据库? 还是不可能由于单线程的JS执行环境? 根据下面的一些评论,这听起来像是一个问题。 有没有办法实现交易? 或者,也许我需要创build一个工作队列或使用基于actor的方法。 我试图了解这种types的问题是如何通过MEAN堆栈解决的。