-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (33 loc) · 893 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const sem = require('semaphore')(5);
const {
connect,
batch
} = require('./lib/main');
module.exports = class BlcakLakeSync {
constructor(username, password) {
this.username = username;
this.password = password;
this.token = '';
}
connect() {
return new Promise((resolve, reject) => {
connect(this.username, this.password).then(token => {
this.token = token;
resolve('Connect Success');
}).catch(err => reject(err));
});
}
batch(type, items) {
return new Promise((resolve, reject) => {
sem.take(() => {
resolve(batch(this.token, type, items));
});
}).then(data => {
sem.leave();
return data;
}).catch(err => {
sem.leave();
return err;
});
}
}