Closed ckpiggy closed 6 years ago
Of course because downloading of the module costs some time.
You need to create a definition file for example wait.js
:
F.wait('mongodb');
@petersirka
I still got the problem
here is my /definitions/wait.js
const F = global.F
console.log('waiting for mognodb', new Date().getTime())
F.wait('mongodb')
console.log('continue ~~~', new Date().getTime())
and I got the logs, it shows the tests run before the database connected
waiting for mognodb 1533919374247
continue ~~~ 1533919374250
====================================================
PID : 6498
Node.js : v8.9.1
Total.js : v2.9.2
OS : darwin 17.7.0
====================================================
Name : Total.js
Version : 1.0.0
Author :
Date : 2018-08-11 00:42:54
Mode : debug
====================================================
http://0.0.0.0:8000/
===================== TESTING ======================
[ TEST: long-run/demo.js ]
Passed ............. long run <long run 0> [0 ms]
Passed ............. next <the next test> [0 ms]
===================== RESULTS ======================
> Passed ......... 2/2
> Failed ......... 0/2
connected to database test
Ohhh you use tests ... there can be a problem with F.wait()
... I'll test it
@petersirka
I also test the example
require('total.js');
F.route('/', function() {
this.plain('Welcome');
});
F.wait('database');
F.wait('users');
F.wait('system');
setTimeout(function() {
F.wait('database');
console.log('database');
}, 3000);
setTimeout(function() {
F.wait('users');
console.log('users');
}, 5000);
setTimeout(function() {
F.wait('system');
console.log('systems');
}, 7000);
// Run the web server
F.http('debug');
I got the log
====================================================
PID : 6609
Node.js : v8.9.1
Total.js : v3.0.0
OS : darwin 17.7.0
Memory : 11.18 MB / 17.96 MB
====================================================
Name : Total.js
Version : 1.0.0
Author :
Date : 2018-08-11 00:56:21
Mode : debug
====================================================
Directory : /Users/ckpiggy/Documents/JS/total_test
node_modules : /Users/ckpiggy/Documents/JS/total_test/node_modules/total.js/
====================================================
http://0.0.0.0:8000/
database
users
systems
It seems the example is broken, too.
It works correctly because F.wait()
works as a toggle
.
// Holds the web server
F.wait('database');
setTimeout(function() {
// Allows processing in the web server
F.wait('database');
}, 1000);
@petersirka I thought the log of example should be like this:
database
users
systems
====================================================
PID : 6609
Node.js : v8.9.1
Total.js : v3.0.0
OS : darwin 17.7.0
Memory : 11.18 MB / 17.96 MB
====================================================
Name : Total.js
Version : 1.0.0
Author :
Date : 2018-08-11 00:56:21
Mode : debug
====================================================
Directory : /Users/ckpiggy/Documents/JS/total_test
node_modules : /Users/ckpiggy/Documents/JS/total_test/node_modules/total.js/
====================================================
http://0.0.0.0:8000/
Did I miss understand F.wait
?
I thought the server will be hold until the F.wait('systems')
unlock the process.
Web server works with F.wait()
but try to create a request in your browser and you will see something like this:
I hope that you understand this feature :-D
@petersirka Oh I see~~
So the problem is tests start before F.wait
completed.
Is there any workaround for this ?
I have fixed it, but you need to install $ npm install total.js@beta
. This was a bug :-/
I inject mongodb module from URL and the server start before database connected.
But if I copy the file in to
/modules
directory, it works.