Skip to content

Commit

Permalink
readme: add .connect() timeout throw info; references #126
Browse files Browse the repository at this point in the history
Signed-off-by: Mario Kozjak <kozjakm1@gmail.com>
  • Loading branch information
mkozjak committed Apr 11, 2019
1 parent 894c4de commit c2e458e
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions README.md
Expand Up @@ -36,7 +36,11 @@ async function run() {
timeout: 1500
}

await connection.connect(params)
try {
await connection.connect(params)
} catch(error) {
// handle the throw (timeout)
}

let res = await connection.exec('uptime')
console.log('async result:', res)
Expand Down Expand Up @@ -100,6 +104,9 @@ connection.connect(params)
}, function(error) {
console.log('promises reject:', error)
})
.catch(function(error) {
// handle the throw (timeout)
})
```

### Generators
Expand All @@ -120,15 +127,23 @@ var params = {

// using 'co'
co(function*() {
yield connection.connect(params)
try {
yield connection.connect(params)
} catch (error) {
// handle the throw (timeout)
}

let res = yield connection.exec(cmd)
console.log('coroutine result:', res)
})

// using 'bluebird'
bluebird.coroutine(function*() {
yield connection.connect(params)
try {
yield connection.connect(params)
} catch (error) {
// handle the throw (timeout)
}

let res = yield connection.exec(cmd)
console.log('coroutine result:', res)
Expand Down Expand Up @@ -161,7 +176,11 @@ async function run() {
timeout: 1500
}

await connection.connect(params)
try {
await connection.connect(params)
} catch (error) {
// handle the throw (timeout)
}

let res = await connection.exec(cmd)
console.log('async result:', res)
Expand Down Expand Up @@ -207,6 +226,7 @@ Telnet client will then basically act like a simple TCP client. Defaults to true
* `debug`: Enable/disable debug logs on console. Defaults to false.

Resolves once the connection is ready (analogous to the ```ready``` event).
Rejects if the timeout is hit.

### connection.exec(data, [options], [callback]) -> Promise

Expand Down

0 comments on commit c2e458e

Please sign in to comment.