Skip to content

Commit 0a7dffa

Browse files
committed
use async/await, change bigsync callback to promise
1 parent 5195de6 commit 0a7dffa

2 files changed

Lines changed: 26 additions & 23 deletions

File tree

src/big-sync.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,11 @@ export function bigSync(project) {
4343
rsync.output(consoleLogFromBuffer, consoleLogFromBuffer);
4444
}
4545

46-
rsync.execute(onComplete);
46+
return new Promise((resolve, reject) => {
47+
rsync.execute((err, ...result) => {
48+
onComplete(err, ...result);
49+
if (err) reject(err);
50+
else resolve(...result);
51+
});
52+
});
4753
}

src/local/index.js

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ const hostname = os.hostname();
2626
const wsEvents = eventsConf.WS.LOCAL;
2727
const fsEvents = eventsConf.FS.LOCAL;
2828

29-
function triggerBigSync(project, params, cb) {
30-
bigSync({
29+
function triggerBigSync(project, params) {
30+
return bigSync({
3131
project: project.project,
3232
excludes: project.excludes,
3333
sourceLocation: ensureTrailingSlash(project.sourceLocation),
3434
destinationLocation: ensureTrailingSlash(project.destinationLocation),
3535
hostname: project.hostname,
3636
username: project.username,
3737
disableDeletion: project.disableDeletion,
38-
}, params, cb);
38+
}, params);
3939
}
4040

4141
export function start(config, projects) {
@@ -80,18 +80,16 @@ function startProject(config, projectConf) {
8080
});
8181

8282
// WS events
83-
wsClient.on(wsEvents.READY, () => {
83+
wsClient.on(wsEvents.READY, async () => {
8484
if (!(config.disableRsync || projectConf.disableRsync)) {
85-
triggerBigSync(projectConf, _.pick(config, ['debug', 'delete']), () => {
86-
fsHelper.watch();
87-
88-
localLog(
89-
text.SYNC_ON_CONNECT,
90-
projectConf.hostname, (projectConf.prefersEncrypted) ? 'using' : 'not using',
91-
'encryption'
92-
);
93-
});
85+
await triggerBigSync(projectConf, _.pick(config, ['debug', 'delete']));
9486
}
87+
fsHelper.watch();
88+
localLog(
89+
text.SYNC_ON_CONNECT,
90+
projectConf.hostname, (projectConf.prefersEncrypted) ? 'using' : 'not using',
91+
'encryption'
92+
);
9593
});
9694

9795
wsClient.on(wsEvents.RECONNECTING, _.partial(_.ary(localLog, 1), text.SYNC_ON_RECONNECT));
@@ -124,16 +122,14 @@ function startProject(config, projectConf) {
124122
wsClient.send(fileChange);
125123
});
126124

127-
fsHelper.on(fsEvents.LARGE, () => {
125+
fsHelper.on(fsEvents.LARGE, async () => {
128126
localLog(text.SYNC_ON_LARGE_CHANGE);
129127
fsHelper.pauseWatch();
130-
131128
if (!(config.disableRsync || projectConf.disableRsync)) {
132-
triggerBigSync(projectConf, { debug: config.debug }, () => {
133-
localLog(text.SYNC_ON_LARGE_CHANGE_DONE);
134-
fsHelper.watch();
135-
});
129+
await triggerBigSync(projectConf, { debug: config.debug });
136130
}
131+
localLog(text.SYNC_ON_LARGE_CHANGE_DONE);
132+
fsHelper.watch();
137133
});
138134
}
139135

@@ -144,17 +140,18 @@ export function once(config, projects, opts) {
144140
return logProjectsNotFound(foundProjects);
145141
}
146142

147-
_.each(foundProjects, (project) => {
143+
_.each(foundProjects, async (project) => {
148144
const localLog = generateLog(project.project, hostname);
149145

150146
localLog(text.SYNC_ON_ONCE);
151147

152148
if (!(config.disableRsync || project.disableRsync)) {
153-
triggerBigSync(project, {
149+
await triggerBigSync(project, {
154150
dry: opts.dryRun,
155151
debug: config.debug,
156-
}, _.partial(localLog, text.SYNC_ON_ONCE_DONE));
152+
});
157153
}
154+
localLog(text.SYNC_ON_ONCE_DONE);
158155
});
159156
}
160157

0 commit comments

Comments
 (0)