MCPcopy Create free account
hub / github.com/transistorsoft/react-native-background-geolocation / doWork

Function doWork

example/HelloWorld/index.js:34–57  ·  view source on GitHub ↗
(eventName)

Source from the content-addressed store, hash-verified

32let doWorkCounter = 0;
33
34const doWork = async (eventName) => {
35 return new Promise(async (resolve, reject) => {
36 if (eventName == 'terminate') {
37 doWorkCounter = 0;
38 // Perform a weird action (for testing) with an interval timer and .startBackgroundTask.
39 const bgTaskId = await BackgroundGeolocation.startBackgroundTask();
40 // Print * tick * to log every second.
41 const timer = setInterval(() => {
42 console.log(`[BGGeoHeadlessTask *][doWork] * tick ${++doWorkCounter}/10 *`);
43 }, 1000);
44 // After 10s, stop the interval and stop our background-task.
45 setTimeout(() => {
46 clearInterval(timer);
47 BackgroundGeolocation.stopBackgroundTask(bgTaskId);
48 resolve();
49 }, 10000);
50
51 } else {
52 // do nothing
53 console.log('[BGGeoHeadlessTask *][doWork]', eventName);
54 resolve();
55 }
56 });
57}
58
59AppRegistry.registerComponent(appName, () => App);

Callers 1

bgGeoHeadlessTaskFunction · 0.85

Calls 3

logMethod · 0.65
startBackgroundTaskMethod · 0.45
stopBackgroundTaskMethod · 0.45

Tested by

no test coverage detected