Skip to content

Commit e88fe5b

Browse files
anyongth0br0
authored andcommitted
Update README with EventEmitter instructions
1 parent 3155801 commit e88fe5b

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

README.md

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,44 @@ Then copy the `libccurl` library from the `build/lib` folder to the main directo
2222

2323
Using this library is fairly simple. You can optionally provide the full path where you have your compiled libccurl.
2424

25+
### API
26+
27+
```
28+
ccurl(
29+
trunkTransaction: string,
30+
branchTransaction: string,
31+
trytes: string[],
32+
minWeightMagnitude: number,
33+
path?: string,
34+
callback?: (error: Error, result: string[]) => void
35+
): EventEmitter | void
2536
```
26-
var ccurl = import('ccurl.interface.js');
2737

28-
ccurl(trunkTransaction, branchTransaction, trytes, minWeightMagnitude, [, path], callback)
38+
When no callback is passed, the method returns an `EventEmitter` which allows you to track job progress. You must call `start` to begin the job.
39+
40+
#### Events:
41+
42+
- `'progress'`: Callback `result` is a number between 0 and 1 as a fraction of `trytes.length`
43+
- `'done'`: Callback `result` is the array of tryte strings
44+
45+
#### Methods:
46+
47+
- `start: () => void`: Begin the job.
48+
49+
#### Example:
50+
51+
```
52+
const ccurl = require('ccurl.interface.js')
53+
54+
const job = ccurl(trunkTransaction, branchTransaction, trytes, minWeightMagnitude, [, path])
55+
56+
job.on('progress', (err, progress) => {
57+
console.log(progress) // A number between 0 and 1 as a percentage of `trytes.length`
58+
})
59+
60+
job.on('done', callback)
61+
62+
job.start()
2963
```
3064

31-
See `example.js`.
65+
See `example.js` or `test/test.js`.

0 commit comments

Comments
 (0)