-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core/local: Extract syncDir from Local & Watchers - DRY - 1 method less in Watcher interface & subclasses - Local doesn't need LocalWatcher anymore to ensure sync dir exists - AtomWatcher module doesn't use fs-extra anymore core/local: Manage syncDir interval check in Local - So we don't need to do it for each watcher subclass (DRY) - AtomWatcher doesn't need syncDir anymore.
- Loading branch information
Showing
5 changed files
with
39 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* @flow */ | ||
|
||
var fs = require('fs') | ||
|
||
/*:: | ||
import type EventEmitter from 'events' | ||
*/ | ||
|
||
module.exports = { | ||
ensureExistsSync, | ||
startIntervalCheck | ||
} | ||
|
||
/** Make sure syncPath actually exists. | ||
* | ||
* In case it doesn't, emit 'syncdir-unlinked' and throws. | ||
* Any other error occuring during the check will be thrown too. | ||
*/ | ||
function ensureExistsSync ({syncPath, events} /*: {syncPath: string, events: EventEmitter} */) /*: void */ { | ||
if (!fs.existsSync(syncPath)) { | ||
events.emit('syncdir-unlinked') | ||
throw new Error('Syncdir has been unlinked') | ||
} | ||
} | ||
|
||
/** Start regularly checking that syncPath actually exists. | ||
* | ||
* Caller should stop the regular check at some point with clearInterval(). | ||
*/ | ||
function startIntervalCheck (context /*: {syncPath: string, events: EventEmitter} */) /*: IntervalID */ { | ||
return setInterval(() => ensureExistsSync(context), 5000) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters