export function delay<T>(ms: number, value?: T): Promise<T> {
return new Promise((resolve) => setTimeout(() => resolve(value), ms));
}
import { injectable } from 'inversify';
import { TimerCallback, ITimer, DelayCalculator } from '../types/timer';
import { delay } from '../../../helpers/delay';
@injectable()
export default class Timer implements ITimer {
private readonly _startDelay: number;
private _enable: boolean;
private counter: number = 0;
constructor(
private _delay: number,
private _nextDelay: DelayCalculator,
private _callback?: TimerCallback,
) {
this._startDelay = _delay;
}
public setCallback = (callback: TimerCallback): void => {
this._callback = callback;
}
public enable = (): void => {
if (!this._callback) {
throw Error('Callback is required for the Timer!');
}
this._enable = true;
this._tick();
}
public disable = (): void => {
if (!this._enable) {
console.warn('You trying to disable timer which is not enabled.');
return;
}
this._enable = false;
}
public reset = (): void => {
this.disable();
this._delay = this._startDelay;
}
private _tick = async (): Promise<void> => {
await delay(this._delay);
if (this._enable) {
this._callback();
this._delay = this._nextDelay(this._delay);
await this._tick();
}
}
}
private void initializeTimer()
{
var dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = new TimeSpan(0, 0, 5);
dispatcherTimer.Start();
}
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
Companies.companies.Clear();
Companies.Get();
grid.Items.Refresh();
}
static class Companies
{
public static System.Data.DataSet companies = new System.Data.DataSet();
public static System.Data.DataView Get()
{
User.connect.Open();
MySqlCommand cmd = new MySqlCommand("SELECT * FROM data", User.connect);
MySqlDataAdapter adapter = new MySqlDataAdapter();
adapter.SelectCommand = cmd;
adapter.Fill(companies);
User.connect.Close();
return new System.Data.DataView(companies.Tables[0]);
}
}
using UnityEngine;
using System.Collections;
public class Block_Script : MonoBehaviour {
private GameObject block;
private float paddingHeight = Screen.height / 100 * 20,
padding = Screen.width / 100 * 5,
width = Screen.width / 100 * 19;
private float paddingTop;
private float paddingLeft;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI () {
paddingTop = paddingHeight + padding;
paddingLeft = padding;
for (int i = 0; i < 16; i++) {
if (i % 4 == 0) {
paddingTop += padding + width;
paddingLeft = padding;
}
if (GUI.Button (new Rect (paddingLeft, paddingTop, width, width), "")) {
print ("You clicked me!");
}
paddingLeft += padding + width;
}
}
}