add cancelable Timeout
This commit is contained in:
		
							
								
								
									
										1
									
								
								test/test.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								test/test.d.ts
									
									
									
									
										vendored
									
									
								
							@@ -1 +0,0 @@
 | 
			
		||||
import 'typings-test';
 | 
			
		||||
							
								
								
									
										30
									
								
								test/test.js
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								test/test.js
									
									
									
									
									
								
							@@ -1,30 +0,0 @@
 | 
			
		||||
"use strict";
 | 
			
		||||
require("typings-test");
 | 
			
		||||
const should = require("should");
 | 
			
		||||
const smartdelay = require("../dist/index");
 | 
			
		||||
describe('smartdelay', function () {
 | 
			
		||||
    it('.delayFor should delay async', function (done) {
 | 
			
		||||
        this.timeout(5000);
 | 
			
		||||
        let timePassed = false;
 | 
			
		||||
        setTimeout(() => {
 | 
			
		||||
            timePassed = true;
 | 
			
		||||
        }, 2000);
 | 
			
		||||
        smartdelay.delayFor(3000).then(() => {
 | 
			
		||||
            should(timePassed).be.true();
 | 
			
		||||
            done();
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
    it('.delayFor should pass on a type', function (done) {
 | 
			
		||||
        this.timeout(5000);
 | 
			
		||||
        let timePassed = false;
 | 
			
		||||
        setTimeout(() => {
 | 
			
		||||
            timePassed = true;
 | 
			
		||||
        }, 2000);
 | 
			
		||||
        let hey = 'heyThere';
 | 
			
		||||
        smartdelay.delayFor(3000, hey).then((stringArg) => {
 | 
			
		||||
            should(stringArg).equal('heyThere');
 | 
			
		||||
            done();
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
});
 | 
			
		||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUVyQixpQ0FBZ0M7QUFFaEM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04sQ0FBQyxDQUFDLENBQUEifQ==
 | 
			
		||||
							
								
								
									
										62
									
								
								test/test.ts
									
									
									
									
									
								
							
							
						
						
									
										62
									
								
								test/test.ts
									
									
									
									
									
								
							@@ -1,31 +1,39 @@
 | 
			
		||||
import 'typings-test'
 | 
			
		||||
 | 
			
		||||
import * as should from 'should'
 | 
			
		||||
import { expect, tap } from 'tapbundle'
 | 
			
		||||
 | 
			
		||||
import * as smartdelay from '../dist/index'
 | 
			
		||||
 | 
			
		||||
describe('smartdelay', function () {
 | 
			
		||||
    it('.delayFor should delay async', function(done) {
 | 
			
		||||
        this.timeout(5000)
 | 
			
		||||
        let timePassed = false
 | 
			
		||||
        setTimeout(() => {
 | 
			
		||||
            timePassed = true
 | 
			
		||||
        },2000)
 | 
			
		||||
        smartdelay.delayFor(3000).then(() => {
 | 
			
		||||
            should(timePassed).be.true()
 | 
			
		||||
            done()
 | 
			
		||||
        })
 | 
			
		||||
    })
 | 
			
		||||
    it('.delayFor should pass on a type', function(done) {
 | 
			
		||||
        this.timeout(5000)
 | 
			
		||||
        let timePassed = false
 | 
			
		||||
        setTimeout(() => {
 | 
			
		||||
            timePassed = true
 | 
			
		||||
        },2000)
 | 
			
		||||
        let hey = 'heyThere'
 | 
			
		||||
        smartdelay.delayFor<string>(3000, hey).then((stringArg) => {
 | 
			
		||||
            should(stringArg).equal('heyThere')
 | 
			
		||||
            done()
 | 
			
		||||
        })
 | 
			
		||||
    })
 | 
			
		||||
tap.test('.delayFor should delay async', async (tools) => {
 | 
			
		||||
  tools.timeout(5000)
 | 
			
		||||
  let timePassed = false
 | 
			
		||||
  setTimeout(() => {
 | 
			
		||||
    timePassed = true
 | 
			
		||||
  }, 2000)
 | 
			
		||||
  await smartdelay.delayFor(3000).then(async () => {
 | 
			
		||||
    // tslint:disable-next-line:no-unused-expression
 | 
			
		||||
    expect(timePassed).to.be.true
 | 
			
		||||
  })
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
tap.test('.delayFor should pass on a type', async (tools) => {
 | 
			
		||||
  tools.timeout(5000)
 | 
			
		||||
  let timePassed = false
 | 
			
		||||
  setTimeout(() => {
 | 
			
		||||
    timePassed = true
 | 
			
		||||
  }, 2000)
 | 
			
		||||
  let hey = 'heyThere'
 | 
			
		||||
  await smartdelay.delayFor<string>(3000, hey).then(async (stringArg) => {
 | 
			
		||||
    expect(stringArg).equal('heyThere')
 | 
			
		||||
  })
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
tap.test('smartdelay.Timeout', async () => {
 | 
			
		||||
  let timeout = new smartdelay.Timeout(2000)
 | 
			
		||||
  await timeout.promise
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
tap.test('smartdelay.Timeout should cancel', async (tools) => {
 | 
			
		||||
  let timeout = new smartdelay.Timeout(60000)
 | 
			
		||||
  timeout.cancel()
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
tap.start()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user