Closed qiuzhong closed 7 years ago
That's because setInterval()
is called on startup. There is, however, no requirement that iotivity-node work with node -e
.
Running test.js with one require('iotivity-node')
statement still hangs.
Yes, I know. There is no way of exiting, because we have no specification for shutting down the stack. Thus, your only way out is process.exit(0)
.
Thanks. With process.exit(0)
it can exit. I am curious why in iotivity-node-1.1.1-3 on Ostro image, node test.js
can return in several seconds.
@gabrielschulhof
For the same require statement:
$ cat test.js
require('iotivity-node');
For iotivity-node 1.1.1-3, node test.js
can return.
# node test.js
# echo $?
0
For iotivity-node 1.2.0-1, node test.js
will hang.
# node test.js
So is this the spec change and acceptable? Could you give us an explanation for this?
IIRC 1.1.1 was structured such that you had to
var ocf = require( "iotivity-node" );
var client = ocf( "client" );
Thus, require( "iotivity-node" )
merely loaded the module, but did not start the setInterval()
until you called ocf( "client" )
.
In contrast, 1.2.0 is structured such that setInterval()
is started as part of the iotivity-node loading process. That is, setInterval()
is started by calling require( "iotivity-node" )
. This is in accordance with the latest spec, whereby no extra function call beyond the require( "iotivity-node" )
is necessary in order to initialize iotivity-node for use either as a client or as a server.
AFAIK there is no requirement that I defer initialization until the library is actually used.
Steps:
In node REPL mode, require('iotivity-node') works well:
Run this require statement in node with -e options, it will hang
It doesn't return.
Test environments