bergson
v0.16.0
Published
Time and scheduling for the web
Downloads
16
Maintainers
Readme
Bergson
What is Bergson?
Bergson is the scheduling system for Flocking and Aconite. It provides a variety of clocks driven by different sources (such as requestAnimationFrame, the Web Audio API, and setInterval), and a priority queue-based scheduler that allows you to queue up one-time and repeating function calls.
Bergson provides a very low-level API for scheduling, and is intended for library developers to build their own rhythmic and pattern-based abstractions on top of.
Examples
Creating a Scheduler with the requestAnimationFrame Clock
var scheduler = berg.scheduler({
components: {
clock: {
type: "berg.clock.requestAnimationFrame",
options: {
freq: 60
}
}
}
});
scheduler.start();
Scheduling one-time events
scheduler.schedule({
type: "once",
time: 30 // 30 seconds from now
callback: function (now) {
// Do something in the future.
}
});
Scheduling repeating events
scheduler.schedule({
type: "repeat",
time: 5, // Start repeating five seconds from now.
freq: 2, // Repeat every two seconds.
end: 20, // Stop repeating 20 seconds from now.
callback: function (now) {
// Do something repeatedly.
}
});
Listening for Clock Events Directly
scheduler.clock.events.onTick.addListener(function (time, rate) {
// Do something every time the clock ticks.
});
Bergson API
Scheduler API
Score Event Specifications
A score event specification is a JSON-type (i.e. plain old, non-prototypal) object that describes the event to be scheduled. It can contain the following properties.
Scheduler Model
For more information on interacting with models, see the Infusion documentation about the Change Applier.
Scheduler Members
Scheduler Methods
Clock API
Clock Members
Clock Methods
Clock Events
Types of Clocks
Building and Testing Bergson
Prerequisites
Bergson uses Node.js, npm, Grunt, and Testem for its build and test tooling. Here's how to get set up:
1. Install the [Node.js](https://nodejs.org/en/) LTS release
3. Install Grunt: <code>npm install -g grunt-cli</code>
4. Install Testem: <code>npm install -g testem</code>
How to Build Bergson
To download all of Bergson's dependencies, build them, and then build Bergson itself, run the following commands:
npm install
grunt
Running Bergson's Test Suite
Bergson's test suite can be run on both Node.js and all of the browsers installed on your computer using Testem:
npm test
If you'd like to run only the Node.js tests, run:
npm run node-test
Or if you only want to run the browser tests:
npm run browser-test
Alternatively, if you'd like to only run the tests in one browser, you can open the test suite tests/unit/all-tests.html
file by hand in your browser.
Community
Bergson is supported by the Flocking community and uses its forums:
Mailing List
The Flocking mailing list is the place to ask questions, share code, and request new features.
Chat
Flocking has an IRC channel, which can also be used to ask questions about Bergson. Join #flocking on irc.freenode.net.
Credits and License
Bergson is written and maintained by Colin Clark. It is dually licensed under the MIT and GPL 2.0 licenses.