New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-native-background-timer

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-background-timer

Emit event periodically (even when app is in the background)

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
40K
decreased by-36.91%
Maintainers
1
Weekly downloads
 
Created
Source

React Native Background Timer

Emit event periodically (even when app is in the background).

Installation

  • npm i react-native-background-timer --save
  • react-native link

Installation using CocoaPods on iOS

  • npm i react-native-background-timer --save
  • add the following to your Podfile: pod 'react-native-background-timer', :path => '../node_modules/react-native-background-timer'

Usage

You can use the setInterval and setTimeout functions. This API is identical to that of react-native and can be used to quickly replace existing timers with background timers.

import BackgroundTimer from 'react-native-background-timer';
// Start a timer that runs continuous after X milliseconds
const intervalId = BackgroundTimer.setInterval(() => {
	// this will be executed every 200 ms
	// even when app is the the background
	console.log('tic');
}, 200);

// Cancel the timer when you are done with it
BackgroundTimer.clearInterval(intervalId);
// Start a timer that runs once after X milliseconds
const timeoutId = BackgroundTimer.setTimeout(() => {
	// this will be executed once after 10 seconds
	// even when app is the the background
  	console.log('tac');
}, 10000);

// Cancel the timeout if necessary
BackgroundTimer.clearTimeout(timeoutId);

Obsolete

Obsolete usage which doesn't allows to use multiple background timers.

import {
  DeviceEventEmitter,
  NativeAppEventEmitter,
  Platform,
} from 'react-native';

import BackgroundTimer from 'react-native-background-timer';
const EventEmitter = Platform.select({
  ios: () => NativeAppEventEmitter,
  android: () => DeviceEventEmitter,
})();
// start a global timer
BackgroundTimer.start(5000); // delay in milliseconds
// listen for event
EventEmitter.addListener('backgroundTimer', () => {
	// this will be executed every 5 seconds
	// even when app is the the background
	console.log('toe');
});
// stop the timer
BackgroundTimer.stop();

Keywords

FAQs

Package last updated on 03 May 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc