Skip to content

Instantly share code, notes, and snippets.

@digitalfiz
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save digitalfiz/3f431dc07ca761389062 to your computer and use it in GitHub Desktop.
Save digitalfiz/3f431dc07ca761389062 to your computer and use it in GitHub Desktop.
library projectx;
import 'dart:io';
class Container {
static Map content = {};
static void set(String name, var contents) {
content[name] = contents;
}
static get(String name) {
var test;
// I need to know if i should be calling this or returning it.
if (content[name] is Function) {
test = content[name]();
} else {
test = content[name];
}
return test;
}
}
main() {
Container.set('test_closure', (){
DateTime now = new DateTime.now();
return now;
});
Container.set('test_string', 'My Test');
Container.set('test_int', 5);
Duration wait = new Duration(seconds:1);
// Do a couple to see its working
print(Container.get('test_closure'));
sleep(wait);
print(Container.get('test_closure'));
sleep(wait);
// Should output 'My Test'.
print(Container.get('test_string'));
// Should output 5.
print(Container.get('test_int'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment