There are two ways you can do this.
1 - the function
node does it all
2 - you add a delay
node after the function
node.
This is a flow that shows both ways.
[{"id":"bbda58b0.80b1d8","type":"function","z":"2a10ff07.234f98","name":"","func":"msg.payload = \"First message\";\nnode.send(msg);\nmsg.payload = \"Last message\"\nreturn msg;","outputs":1,"noerr":0,"x":330,"y":1860,"wires":[["46e569fc.bd4918"]]},{"id":"e97297e2.98a31","type":"inject","z":"2a10ff07.234f98","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":1810,"wires":[["db5ebf42.239088","bbda58b0.80b1d8"]]},{"id":"46e569fc.bd4918","type":"delay","z":"2a10ff07.234f98","name":"Delay","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"5","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":480,"y":1860,"wires":[["34c57a8d.7684d6"]]},{"id":"db5ebf42.239088","type":"function","z":"2a10ff07.234f98","name":"","func":"//\n// Note the position of the first and last messages.\n//\nsetTimeout(function(){\n msg.payload = \"last message\";\n node.send(msg);\n}, 5000); // This is how many milliseconds to wait.\n\nmsg.payload = \"first message\";\nreturn msg;","outputs":1,"noerr":0,"x":330,"y":1810,"wires":[["7c1fbeb3.10b04"]]},{"id":"34c57a8d.7684d6","type":"debug","z":"2a10ff07.234f98","name":"Second way","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":670,"y":1860,"wires":[]},{"id":"7c1fbeb3.10b04","type":"debug","z":"2a10ff07.234f98","name":"First way","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":660,"y":1810,"wires":[]}]
The only problem is that there is an initial 5
second delay for the first message too.