Sleep can be used in a Node JS function, such as below
- /*** author: vincent.balfe@cloud-connect.ie* @param seconds: literal - to be converted to ms* @return JSON IO - SUCCESS or FAIL*/module.exports = async function( context, basicIO ){if (basicIO.getParameter("seconds")){// Get 'seconds' paramvar secs = (parseInt(basicIO.getParameter("seconds"))) * 1000;await sleep(secs)function sleep(ms) {return new Promise((resolve) => {setTimeout(resolve, ms);});}basicIO.write("SUCCESS");}else{basicIO.write("FAIL");}}
This can then be called multiple times ( no more than 5, and no longer than 1 minute sleep-time in total ) from a regular deluge function like so:
- info "Start: " + now;
- if( (thisapp.sleep_function("1")).contains("SUCCESS") ){
- info "Step 1 ( 1 second ): " + now;
- if( (thisapp.sleep_function("2")).contains("SUCCESS") )
- {
- info "Step 2 ( 2 seconds ): " + now;
- if( (thisapp.sleep_function("3")).contains("SUCCESS"))
- {
- info "Step 3 ( 3 seconds ): " + now;
- if( (thisapp.sleep_function("4")).contains("SUCCESS"))
- {
- info "Step 4 ( 4 seconds ): " + now;
- if( (thisapp.sleep_function("30")).contains("SUCCESS"))
- {
- info "Step 5 ( 30 seconds ): " + now;
- }
- }
- }
- }
- }
Result
- Start: 13-May-2022 09:42:50
- Step 1 ( 1 second ): 13-May-2022 09:42:52
- Step 2 ( 2 seconds ): 13-May-2022 09:42:55
- Step 3 ( 3 seconds ): 13-May-2022 09:42:59
- Step 4 ( 4 seconds ): 13-May-2022 09:43:03
- Step 5 ( 30 seconds ): 13-May-2022 09:43:33